jsoup 使用总结3--高级用法之 not

jsoup 使用总结3--高级用法之 not

大部分时候,咱们使用jsoup解析网页的时候,都是直接找到某一类元素,或者按某种selector查询;具体使用方法能够参考jsoup官网文档html

例子代码:this

String html = "<p>An <a href='http://example.com/'><b>example</b></a> link. this is other <a href="http://example.com/abc" style="color:red">linkB</a></p>";
Document doc = Jsoup.parse(html);
Elements links = doc.select("a");
for(Element e : links)
{
   String linkHref = link.attr("href"); 
   ...
}
Element link = doc.select("a").first();

如何咱们想直接找到example的DOM元素呢,有没有其余方式
固然有了,下面是代码:code

Element example = doc.select("a").not("[style]").first();

固然这里的例子比较简单,可是not的用法我是交给你了呀。htm

但愿能解决你手边的问题。文档

另外推荐阅读jsoup的官网文档,我80%的问题都在官网找到了方法。get

相关文章
相关标签/搜索