jsoup是否支持xpath? [英] Does jsoup support xpath?
本文介绍了jsoup是否支持xpath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正在进行一些与将xpath支持添加到jsoup相关的工作 https://github.com/jhy/jsoup/pull/80 .
There's some work in progress related to adding xpath support to jsoup https://github.com/jhy/jsoup/pull/80.
- 它在起作用吗?
- 我如何使用它?
推荐答案
JSoup 尚不支持 XPath ,但是您可以尝试.
JSoup doesn't support XPath yet, but you may try XSoup - "Jsoup with XPath".
以下是从Github项目站点引用的示例(链接):
Here's an example quoted from the projects Github site (link):
@Test
public void testSelect() {
String html = "<html><div><a href='https://github.com'>github.com</a></div>" +
"<table><tr><td>a</td><td>b</td></tr></table></html>";
Document document = Jsoup.parse(html);
String result = Xsoup.compile("//a/@href").evaluate(document).get();
Assert.assertEquals("https://github.com", result);
List<String> list = Xsoup.compile("//tr/td/text()").evaluate(document).list();
Assert.assertEquals("a", list.get(0));
Assert.assertEquals("b", list.get(1));
}
您还将在其中找到XSoup支持的XPath功能和表达式的列表.
There you'll also find a list of features and expressions of XPath that are supported by XSoup.
这篇关于jsoup是否支持xpath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文