1

我正在尝试使用结果列类来抓取 div 内的所有内容。

这是我用于查询的代码,它不返回任何数据:

Elements el_name = doc.select(".div.results-column a.no-tracks.url"); 
Elements el_phone = doc.select(".div.results-column  span.business-phone.phone");
Elements el_address = doc.select(".div.results-column span.street-address");
Elements el_city = doc.select(".div.results-column span.locality");
Elements el_state = doc.select(".div.results-column span.region");
Elements el_postalcode = doc.select(".div.results-column span.postal-code");

此处概述了选择器:http: //jsoup.org/cookbook/extracting-data/selector-syntax

例子:

<div class='results-column'>
   <div class='listing-content'>
   <span class='business-phone phone'>(111) 222-333</span><br>
   <span class='no-tracks url'>www.example.com</span><br>
   <span class='street-address'>29129 Sesame Street</span><span class='locality'>, Sesame City</span><br>
   [Rest of information from result1 would be here, I don't need to list every single thing on SO I hope]
   </div>
   <span class='business-phone phone'>(111) 222-333</span><br>
   <span class='no-tracks url'>www.example.com</span><br>
   <span class='street-address'>29129 Sesame Street</span><span class='locality'>, Sesame City</span><br>
   [Rest of information from result2 would be here, I don't need to list every single thing on SO I hope]
   </div>
</div>

我不能用祖先子运算符选择某个类的 div 吗?

4

1 回答 1

1

它应该是

  doc.select("div.results-column a.no-tracks.url");

不是

  doc.select(".div.results-column a.no-tracks.url");

标记前的点用作类选择器。HTML 标签不带点(其他选择器也一样)。

于 2012-10-18T03:59:35.870 回答