【问题标题】:Java Parsing website [closed]Java解析网站[关闭]
【发布时间】:2016-02-10 23:49:42
【问题描述】:

我正在尝试解析并从给定网站获取一些特定链接。我在这里检查了很多关于 jsoup 的问题,并尝试了可能是解决方案的问题,但我没有成功,我开始认为我试图解析的网站可能是某个特定的网站。这是 HTML 的一大块,我想从 HTML 中的所有文章类中获取所有链接:

<article id="item_65190842" class="media item_row ptm pbm nmt" itemscope itemtype="http://schema.org/Offer">  
<a title="Flera bilder" itemprop="url" tabindex="50" href="http://www.blocket.se/vastmanland/Volkswagen_Passat_2_0_TDI_DSG_140_Hk_Sportlin_65190842.htm?ca=11&w=3" class="pull-left item-link nohistory image_container  has_multiple_images" data-js="item_link"><ul class="object-attribute-badges"></ul><img src="https://cdn.blocket.com/static/0/lithumbs/41/4164545596.jpg" title="Flera bilder" alt="Flera bilder" width="169px" height="126px" class="item_image"/></a>

<div class="media-body desc" itemprop="itemOffered" itemscope><header class="clearfix"><div class="pull-left "><a class="label label-default mrxs" itemprop="url" onclick="return xt_click(this,'C','11','Butiksbadge','N')" href="http://www.blocket.se/bildepan-i-morgongava?ca=11">Butik</a>Västmanland</div><time datetime="2016-02-10 13:47:01" pubdate itemprop="datePublished" class="pull-right">Idag  13:47</time></header><h1 class="h5 media-heading ptxs" itemprop="name"><a href="http://www.blocket.se/vastmanland/Volkswagen_Passat_2_0_TDI_DSG_140_Hk_Sportlin_65190842.htm?ca=11&w=3" title="Volkswagen Passat 2.0 TDI DSG 140 Hk Sportlin" itemprop="url" tabindex="50" class="item_link">Volkswagen Passat 2.0 TDI DSG 140 Hk Sportlin -08</a></h1><p itemprop="price" class="list_price font-large">62 900:-</p><footer><div class="pull-right addon"></div></footer></div>
</article>

我想得到&lt;a title="Flera bilder"里面的链接

这是我要解析的网页

http://www.blocket.se/hela_sverige/bilar/

【问题讨论】:

  • 你有一个空链接
  • 我认为它现在已修复

标签: java html parsing jsoup


【解决方案1】:

假设您有使用 Jsoup 的 Document 对象。这就是你需要的。

Elements links = doc.select("a[title=Flera bilder]")
for(Element link : links){
    //This is the absolute link that you need. 
    String absHref = link.attr("abs:href");
}

参考Jsoupcookbook进一步参考

【讨论】:

  • 成功了!!!谢谢老哥
  • 没问题。请注意,如果有任何通过 Javascript 加载的内容。 Jsoup 不起作用
猜你喜欢
  • 2012-09-09
  • 2017-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-14
  • 1970-01-01
  • 1970-01-01
  • 2010-09-19
相关资源
最近更新 更多