[英]Selecting certain <tr> tag with JSoup
I am new to JSoup and have been working with it for a few days now with no problems, until I came across this one. 我是JSoup的新手,已经使用它几天了,现在没有任何问题,直到遇到了这个。 I'm trying to get all the
<tr>
tags from a table where the <tr>
s have a child <td>
tag with a certain class. 我正在尝试从表中获取所有
<tr>
标记,其中<tr>
包含具有特定类的子<td>
标记。
I am trying to retrieve the data from this website , this is what I'm trying: 我正在尝试从此网站检索数据,这是我正在尝试的:
document.select("#partedenieve tr:has(td.zonas)");
I don't know if it works because the problem here is that if you select just #partedenieve tr
it only returns the <tr>
s on the thead
. 我不知道它是否有效,因为这里的问题是,如果只选择
#partedenieve tr
它只会在thead
上返回<tr>
。 I've tried some other queries, but when I finally achieve to get <tr>
s from the tbody it won't return all the <tr>
tags either. 我尝试了其他一些查询,但是当我最终实现从tbody中获取
<tr>
时,它也不会返回所有<tr>
标记。
I don't know if this problem may be related to the rowspan tag present on the <tr>
s I want to get... but I've had no luck so far. 我不知道这个问题是否可能与我想要获得的
<tr>
上存在的rowspan标签有关...但是到目前为止我还没有运气。
Thanks in advance for your replies. 提前感谢您的回复。
Try: 尝试:
Elements elts = document.select("tr > td.class");
This will return all td elements with the given class. 这将返回给定类的所有td元素。 So you just have to get each unique parent:
因此,您只需要获取每个唯一的父代:
List<Element> list = new ArrayList<Element>();
for (Element elt : elts) {
if (!list.contains(elt) {
list.add(elt);
}
}
Now, your list
object contains all of your tr elements. 现在,您的
list
对象包含所有tr元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.