【问题标题】:How do you use JSoup to find elements (HTML parsing)?如何使用 JSoup 查找元素(HTML 解析)?
【发布时间】:2012-04-18 01:10:55
【问题描述】:

我知道在 Jsoup 中,当你想找到某个带有链接的 Element 时,你可以这样做:

Document doc = Jsoup.parse(text); 
Element links = doc.select("[href]"); 

但是,这会将所有链接带到页面中的每个网站...

但是如果我有多个链接,我只想检索那些专门链接到谷歌的链接。例如:

<a href="http://www.google.com">Google</a>
<a href="http://www.bing.com">Bing</a>
<a href="http://www.google.com">Another Google</a> 

而且我希望它只接收那些有 google 的人。我试着做这样的事情:

Element links = doc.select("[href=\"http://www.google.com\"]"); 

但这不起作用...有人有建议吗?

【问题讨论】:

    标签: android html-parsing jsoup elements


    【解决方案1】:

    你有没有简单地尝试过:

    Element links = doc.select("[href=http://www.google.com]"); 
    //Or,
    Element links = doc.select("a[href=http://www.google.com]");
    
    //Or with the 'attribute contains' form, the most likely to work:
    Element links = doc.select("a[href*=google]");
    

    【讨论】:

      猜你喜欢
      • 2016-04-18
      • 2015-01-03
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-01
      • 2012-06-19
      相关资源
      最近更新 更多