HTMLCleaner是否支持XPath position((函数和使用谓词来表示位置?
我的代码如下:
HtmlCleaner htmlCleaner = new HtmlCleaner();
String sourceUrl = "http://jobs.alaska.gov/RR/WARN_notices.htm";
URL url = new URL(sourceUrl);
URLConnection urlConnection = url.openConnection();
TagNode rootTagNode = htmlCleaner.clean(new InputStreamReader(urlConnection.getInputStream()));
String xpathOne = "//table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[1]/td/div/span/text()";
// String xpathTwo = "//table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[3]/td/div/span/text()";
Object[] xPathNodes = rootTagNode.evaluateXPath(xpathOne);
// Object[] xPathNodes = rootTagNode.evaluateXPath(xpathTwo);
for(Object object : xPathNodes) {
System.out.println(object);
}
xPathOne 正确执行并返回带有标题的表行。 xPathTwo 不返回任何内容,但它应返回表中的第一行数据。任何帮助将不胜感激。谢谢。
我认为那里没有span
元素,所以也许缩短通往//table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[3]/td/div/text()
的道路是你想要的。