jsoup 从表头获取一个元素


<th "data-next="/?operator=comcast&from=hbo#guide" >
<a href="/hbo/" title="HBO">
  <div>
    <img src="//comcast.com/channel_logo/hbo.png?0">
  </div>
  <span>HBO</span>
</a>
</th>
<th "data-next="/?operator=att&from=fox#guide" >
<a href="/fox/" title="fox">
  <div>
    <img src="//att.com/channel_logo/fox.png?0">
  </div>
  <span>FOX</span>
</a>
</th>

我想获得data-next中的每个链接,所以我希望拥有: /?operator=comcast&from=hbo#guide/?operator=att&from=fox#guide.但我在解释方面有问题,因为我不知道data-next是什么。它不是一个属性,也不是一个元素,所以我不确定我应该在jsoup中使用什么。我将不胜感激任何帮助

编辑:

整个表头如下所示:

<thead class="channelLogos"> 
 <tr>  
  <th "data-next="/?operator=comcast&from=hbo#guide"> <a href="/hbo/" title="HBO"> 
    <div> 
     <img src="//comcast.com/channel_logo/hbo.png?0"> 
    </div> <span>HBO</span> </a> </th>(...) 

当我这样做时:

Elements elts = doc.select("thead.channelLogos th")
for(Element elt : elts) {
   System.out.println(elt.absUrl("data-next"));
}//elts stores th elements but doesn't print anything

但像这样:

Elements elts = doc.select("thead.logaStacji th[data-next]");

elts为空(大小 = 0

试试这个:

String html = loadHTML(...);
Document doc = Jsoup.parse(html);
Elements elts = doc.select("th[data-next]");
for(Element elt : elts) {
    // Get absolute url stored in data-next attribute
    System.out.println(elt.absUrl("data-next"));
}

相关内容