[英]Element id in the loop (JSOUP)
這是我的代碼:
Element current = doc.select("tr[class=row]").get(5);
for (Element td : current.children()) {
System.out.println(td.text());
}
如何在循環中獲取Element ID?
謝謝!
在HTML中, id
是常規屬性,因此您可以簡單地調用td.attr("id")
:
Element current = doc.select("tr.row").get(5);
for (Element td : current.children()) {
System.out.println(td.attr("id"));
}
請注意,還有一個用於類的選擇器: tr.row
。
JSoup支持許多CSS選擇器,因此可以使用單個選擇器重寫它:
Elements elements = doc.select("tr.row:nth-of-type(6) > td");
for (Element element : elements) {
System.out.println(element.id());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.