0
選擇,我有以下的HTML表格元素:Jsoup條件
<table class='myTable'>
<tbody>
<tr>
<th>header1</th>
<td>data1</td>
</tr>
<tr>
<th>header2</th>
<td><table><tbody><tr><th>subheader1</th><td>subdata1</td></tr>
<tr><th>subheader2</th><td>subdata2</td></tr>
</tbody></table></td>
</tr>
<tr>
<th>header3</th>
<td>data3</td>
</tr>
....
<tbody>
</table>
我怎麼會在桌子上,在那裏這些頭的下一個TD元素不包含表中選擇頭。在上述情況下,只能選擇標頭header1
和header3
。
我目前所面對的是
Elements elements = doc.select("table[class=" + myTable + "]);
Element table;
if(elements.size()>0){
table = elements.get(0);
}
else{
return someMyObj;
}
Iterator<Element> ite = table.select("th AND SOME CONDITIONS").iterator();
while(ite.hasNext()){
Element header = ite.next();
}
謝謝。它按我的預期工作。就像你剛纔說的那樣,我可能會嘗試從Jsoup中擠出很多東西。 – user200340
Naah,我說得太早,因爲我認爲它不能完成。然後我嘗試了這個解決方案並且必須編輯答案;) – soulcheck