select tr 来自 JSOUP 中的 table
select tr from a table in JSOUP
我想从 table 中获取 TR 标签作为元素,正如我所解释的那样。但是当我使用
Elements elementObj = doc.select("table").select("tr");
它正在获取 table 中存在的所有 TR 标签。但我只想将父 TR 标签作为我突出显示的元素,而不是子 TR 标签。任何人都请帮助我!
<table>
<tr>//This tr as Element
<td>
<table>
<tr>
!!!NOT these tr
</tr>
</table>
</td>
</tr>
<tr>//This tr as Element
<td>
<table>
<tr>
!!!NOT these tr
</tr>
</table>
</td>
</tr>
使用children()
,它只给你直接节点。所以像这样使用它:
Elements elementObj = doc.select("table").first().children().select("tr");
假设你只有一个 table
元素,如果有很多,你应该首先获取所有 table
元素,然后遍历它们并在每个元素上调用 children()
他们。
我使用以下代码解决了这个问题:
Elements elementobj = doc.select("table>tr");
这得到第一级children。
我想从 table 中获取 TR 标签作为元素,正如我所解释的那样。但是当我使用
Elements elementObj = doc.select("table").select("tr");
它正在获取 table 中存在的所有 TR 标签。但我只想将父 TR 标签作为我突出显示的元素,而不是子 TR 标签。任何人都请帮助我!
<table>
<tr>//This tr as Element
<td>
<table>
<tr>
!!!NOT these tr
</tr>
</table>
</td>
</tr>
<tr>//This tr as Element
<td>
<table>
<tr>
!!!NOT these tr
</tr>
</table>
</td>
</tr>
使用children()
,它只给你直接节点。所以像这样使用它:
Elements elementObj = doc.select("table").first().children().select("tr");
假设你只有一个 table
元素,如果有很多,你应该首先获取所有 table
元素,然后遍历它们并在每个元素上调用 children()
他们。
我使用以下代码解决了这个问题:
Elements elementobj = doc.select("table>tr");
这得到第一级children。