29
A
回答
11
JSoup不支持的XPath,但你可以嘗試XSoup - 「Jsoup使用XPath」。
下面是從項目Github上的網站(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表達式的列表。
1
還沒有,但JsoupXpath具有使it.For例如項目,
String xpath="//div[@id='post_list']/div[./div/div/span[@class='article_view']/a/num()>1000]/div/h3/allText()";
String doc = "...";
JXDocument jxDocument = new JXDocument(doc);
List<Object> rs = jxDocument.sel(xpath);
for (Object o:rs){
if (o instanceof Element){
int index = ((Element) o).siblingIndex();
System.out.println(index);
}
System.out.println(o.toString());
}
相關問題
- 1. libxml2是否支持XPath 2.0?
- 2. JSoup是否支持getComputedStyle或等價的?
- 3. jsoup是否支持restful/rest請求
- 4. tinyxpath 1.3.1是否支持xpath 2.0?
- 5. XPath是否支持WHERE子句?
- 6. NodeJS xpath庫是否支持XPath查詢表達式?
- 7. Watin支持xPath嗎?
- 8. 是否支持groovvy
- 9. 是否支持SSI?
- 10. 是否支持DataGrid?
- 11. 是否支持MSNP9?
- 12. 是否支持ARC?
- 13. Android是否支持手錶支持NFC
- 14. Python中的XPATH Twisted是否支持這種語法:「/message/body[.='test']」?
- 15. 是否支持MS .net xpath實現的格式編號?
- 16. JDK 6是否支持XPath 2.0的所有功能?
- 17. Jackrabbit是否支持XPath聯合(|)運算符?
- 18. LXML不支持XPath的
- 19. Xerces-C中的XPath支持
- 20. 使Apache Xerces支持Xpath 2.0
- 21. Windows Metro:XAML支持XPath綁定
- 22. JAXB/MOXy XPath謂詞支持
- 23. XElement是否支持nil = true
- 24. GWT是否支持php?
- 25. Cordova是否支持Tizen?
- 26. TypeScript是否支持TouchEvent?
- 27. Confluence是否支持中文?
- 28. Arduino是否支持線程?
- 29. 是否libevent支持netlink socket
- 30. GraphEngine是否支持RDF?
目前的信息在這個題目勿庸置疑那裏:https://stackoverflow.com/questions/11816878/jsoup- css-selector-code-xpath-code-included https://stackoverflow.com/questions/16335820/convert-xpath-to-jsoup-query https://stackoverflow.com/questions/11791596/how-to-get- https://groups.google.com/forum/?fromgroups#!topic/jsoup/lj4_-EJwH1Q的絕對路徑元素 –