0

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 不返回任何内容,但它应该返回表中的第一行数据。任何帮助将不胜感激。谢谢。

4

1 回答 1

0

我认为那里没有span元素,所以也许缩短路径//table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[3]/td/div/text()是你想要的。

于 2019-09-09T11:14:49.027 回答