如果是XPath的使用可以查看 https://blog.csdn.net/qq_34627002/article/details/83309209
今天说的 evaluateXPath是属于TagNode类中的方法,它包含类的写法 有所不同
// XPath包含多个类名是这样
xPath.evaluate("//div[contains(@class,'s-top-left')]//a", dom, XPathConstants.NODESET);
// TagNode这样使用会报错
ns = node.evaluateXPath("//div[contains(@class,'s-top-left')]//li");
// 正确方法
ns = node.evaluateXPath("//div['ddd' < @class]//li");
其实可以点击该方法进入看注释 ,注释中 <li>data(//a['v' < @id])</li>就说了包含类名的用法
/**
* Evaluates XPath expression on give node. <br>
* <em>
* This is not fully supported XPath parser and evaluator.
* Examples below show supported elements:
* </em> <code>
* <ul>
* <li>//div//a</li>
* <li>//div//a[@id][@class]</li>
* <li>/body/*[1]/@type</li>
* <li>//div[3]//a[@id][@href='r/n4']</li>
* <li>//div[last() >= 4]//./div[position() = last()])[position() > 22]//li[2]//a</li>
* <li>//div[2]/@*[2]</li>
* <li>data(//div//a[@id][@class])</li>
* <li>//p/last()</li>
* <li>//body//div[3][@class]//span[12.2<position()]/@id</li>
* <li>data(//a['v' < @id])</li>
* </ul>
* </code>
*
* @param xPathExpression
* @return result of XPather evaluation.
* @throws XPatherException
*/
public Object[] evaluateXPath(String xPathExpression) throws XPatherException {
return new XPather(xPathExpression).evaluateAgainstNode(this);
}











网友评论