zoukankan      html  css  js  c++  java
  • jsoup 使用总结3--高级用法之 not

    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%的问题都在官网找到了方法。

  • 相关阅读:
    SpringMVC听课笔记(一:SpringMVC概述)
    IDEA快捷键
    Java学习方法以及eclipse看jdk源码
    SpringMVC参数绑定
    正向代理、反向代理
    代理模式
    面试准备
    一致性哈希
    synchronized的底层探索
    哈夫曼编码
  • 原文地址:https://www.cnblogs.com/jerrychen/p/4667309.html
Copyright © 2011-2022 走看看