嗨,我试着为了一个小工具的目的,使用xsoup来查找元素的数量。在这种情况下,当xpath使用任何元素属性进行搜索时,它工作正常,但使用元素的文本进行搜索时,它会抛出错误。有人能帮我吗?如果有其他方法可以从保存的html文件的文档中找到元素的计数,那就很有帮助了。
代码段
Document doc=HtmlPage.getHTML("https://www.techlistic.com/p/demo-selenium-practice.html", "", "https://phptravels.com");
String xpath="//td[text()=\"UAE\"]";
int count=Xsoup.compile(xpath).evaluate(doc).list().size();
System.out.println(count);
例外
Exception in thread "main" org.jsoup.select.Selector$SelectorParseException: Could not parse query 'td[text()="UAE"]': unexpected token at 'text()="UAE"'
at us.codecraft.xsoup.xevaluator.XPathParser.byFunction(XPathParser.java:260)
at us.codecraft.xsoup.xevaluator.XPathParser.consumePredicates(XPathParser.java:231)
at us.codecraft.xsoup.xevaluator.XPathParser.findElements(XPathParser.java:163)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:76)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:408)
at us.codecraft.xsoup.xevaluator.XPathParser.combinator(XPathParser.java:110)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:74)
at us.codecraft.xsoup.xevaluator.XPathParser.parse(XPathParser.java:408)
at us.codecraft.xsoup.Xsoup.compile(Xsoup.java:25)
at demo.TestException.main(TestException.java:36)
暂无答案!
目前还没有任何答案,快来回答吧!