gpt4 book ai didi

java - 如何使用 Jsoup 选择元素

转载 作者:行者123 更新时间:2023-11-30 04:01:39 24 4
gpt4 key购买 nike

我有一个表,我想在其中迭代根 tbody 中的行 (tr),而不是子级中的行

我尝试了这个但没有成功:

Elements tableRows = table.select("tr");

这个 get tr 也在它的 child 中,所以我有重复的

Elements tableRows = table.select("tbody > td:first-child");

这也不起作用

这是我的 table :

<table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">
<tbody>
<tr>
<td class="head">Rank</td>
<td class="Head">&nbsp;</td>
<td class="Lhead">Club</td>
<td class="head">Nation</td>
<td class="head">Rank points</td>
<td class="head">Five best results (by points)</td>
</tr>
<tr>
<td class="playerB">60. (1.)</td>
<td class="Lplayer"><a href="player.aspx?id=260161">Imrich Blasko</a></td>
<td class="Lplayer"><a href="club.aspx?id=260008">THC Blue Dragon Kosice</a></td>
<td class="player"><img src="flags/SVK.gif" alt="SVK" /></td>
<td class="playerB">3&nbsp;398</td>
<td class="Lplayer">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=14379">World Championships 2013</a></td>
<td class="Rplayer">817</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=14192">Czech Open 2012</a></td>
<td class="Rplayer">674</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=15844">Czech Open 2013</a></td>
<td class="Rplayer">668</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=16982">Slovak Championships 2013</a></td>
<td class="Rplayer">621</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=17781">Bratislava Cup 2013</a></td>
<td class="Rplayer">617</td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td colspan="6">
<hr color="#008080" width="100%" /></td>
</tr>
<tr>
<td class="playerB">159. (2.)</td>
<td class="Lplayer"><a href="player.aspx?id=650633">Tibor Valachovic ml.</a></td>
<td class="Lplayer"><a href="club.aspx?id=260007">SHK Skalica</a></td>
<td class="player"><img src="flags/SVK.gif" alt="SVK" /></td>
<td class="playerB">2&nbsp;847</td>
<td class="Lplayer">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=15844">Czech Open 2013</a></td>
<td class="Rplayer">639</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=16318">Brno 2013</a></td>
<td class="Rplayer">594</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=17784">Brno 2014</a></td>
<td class="Rplayer">583</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=16982">Slovak Championships 2013</a></td>
<td class="Rplayer">569</td>
</tr>
<tr>
<td class="Lplayer"><a href="tournament.aspx?id=12576">Czech Open 2011</a></td>
<td class="Rplayer">461</td>
</tr>
</tbody>
</table></td>
</tr>
<tr>
<td colspan="6">
<hr color="#008080" width="100%" /></td>
</tr>
</tbody>
</table>

最佳答案

尝试:

Elements tableRows = table.select(":root > tbody > tr");

关于java - 如何使用 Jsoup 选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21849039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com