假设我有一个格式不正确的 html 页面:
<table>
<thead>
<th class="what_I_need">Super sweet text<th>
</thead>
<tr>
<td>
I also need this
</td>
<td>
and this (all td's in this and subsequent tr's)
</td>
</tr>
<tr>
...all td's here too
</tr>
<tr>
...all td's here too
</tr>
</table>
在 BeautifulSoup 上,我们能够得到<th>
然后调用findNext("td")
. Nokogiri 有next_element
调用,但这可能不会返回我想要的(在这种情况下,它会返回tr
元素)。
有没有办法过滤next_element
Nokogiri 的电话?例如next_element("td")
?
编辑
为了澄清起见,我将查看许多站点,其中大多数以不同的方式形成错误。
例如,下一个站点可能是:
<table>
<th class="what_I_need">Super sweet text<th>
<tr>
<td>
I also need this
</td>
<td>
and this (all td's in this and subsequent tr's)
</td>
</tr>
<tr>
...all td's here too
</tr>
<tr>
...all td's here too
</tr>
</table>
我不能假设任何结构,除了在具有类的项目下面会有tr
swhat_I_need