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

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

例子代码:

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元素呢,有没有其他方式
当然有了,下面是代码:

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

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

希望能解决你手边的问题。

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

相关文章:

  • 2022-12-23
  • 2021-08-21
  • 2021-05-15
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-05-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-18
  • 2021-12-29
  • 2021-12-02
  • 2022-12-23
  • 2021-07-20
相关资源
相似解决方案