好吧,我想不出任何更简单的方法来表达这个问题,但它并不像看起来那么复杂。基本上我有一个小项目可以帮助自己在工作场所提升(目前的技术支持代理,正在寻找兼职网络开发:我现在很渴望代码并且技术支持并不令人满意)
所以我说我会做一个小程序,当出现问题或站点问题时,它会更新技术代理。它从一个名为 outage 的小网页获取信息(在我看来这是灾难性的,wcc 验证器上有 177 个错误)
网络开发人员不会只提供表格和 ID,某种安全漏洞?不知道怎么做,但我不会质疑我上面的人。试图与他们合作,而不是反对他们。
表本身没有id,但里面的列有(span id),例如
<table width="100%" border="0">
<tbody>
<tr id="title">
<td width="9%">Date/Time</td>
<td width="24%">program/site</td>
<td width="5%">Ticket</td>
<td width="*">Issue</td>
<td width="2%">More</td>
</tr>
<tr>
<td><span id="date">2011-01-27 17:32</span></td>
<td><span id="site"><a id="fus_00001"></a>sample area or program affected</span></td>
<td><span id="site"><a href="https://sample php file i cant give you" target="_blank">12345671</a></span></td>
<td><span id="issue">problem identified/ investiating</span></td>
<td><span id="ticket"></span></td>
</tr><tr>
我为此使用java,并且出于所有意图和目的,它绘制,做我需要的一切。解析我正在使用 htmlunit 2.8 的信息
这是我目前正在使用的代码。我只是不知道如何在没有 id 的情况下获取这些表。
String update = "blank";
final WebClient webClient = new WebClient();
webClient.setJavaScriptEnabled(false);// javascript causes some serious problems.
webClient.setCssEnabled(false);
HtmlPage page;
try
{
URL outageURL = new URL("file:\\C:\\Users\\MYDRIVE\\Desktop\\version control\\OUTAGE\\Outages.htm"); //local drive at home
page = webClient.getPage(outageURL);
//final HtmlTable table = page.getHtmlElementById("outages");// if the table had the id "outages, this would be perfect! but alas it doesnt
final HtmlTable table = page.get//the cells int eh table by some other means
update = (table.getCellAt(1,0).asText() + " " + table.getCellAt(1,1).asText() + " " + table.getCellAt(1,2).asText() + " " + table.getCellAt(1,3).asText());
// above code takes the cells and combines them
} catch and everything else
return update;
所以底线,有没有人知道如何在没有 id 的情况下通过其他方式访问这些表。也许跨度ID?ps 我查看了 api hor html 单元,不太确定我能找到任何有用的东西。
final String stringHtmlTable = page.getPage().asXml();
如果我要这样做,我将如何使用 xpath 根据标记的响应将我带到所需的单元格。ps对xml一点也不熟悉