[英]Element id in the loop (JSOUP)
Here is my code: 这是我的代码:
Element current = doc.select("tr[class=row]").get(5);
for (Element td : current.children()) {
System.out.println(td.text());
}
How can I get an Element id in the loop? 如何在循环中获取Element ID?
Thanks! 谢谢!
In HTML id
is a normal attribute, so you can simply call td.attr("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"));
}
Note that there is also a selector for classes: tr.row
. 请注意,还有一个用于类的选择器: tr.row
。
JSoup supports many of the CSS selectors, so this could be rewritten with a single selector: 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.