【发布时间】:2011-12-13 13:34:52
【问题描述】:
在我的 Rails 应用程序中,我有如下 HTML,在 Nokogiri 中解析。
我希望能够选择 HTML 块。例如,如何使用 XPath 或 CSS 选择属于 <sup id="21"> 的 HTML 块?假设在真正的 HTML 中不存在带有******** 的部分。
我想通过<sup id=*> 拆分 HTML,但问题是节点是兄弟节点。
<sup class="v" id="20">
1
</sup>
this is some random text
<p></p>
more random text
<sup class="footnote" value='fn1'>
[v]
</sup>
# ****************************** starting here
<sup class="v" id="21">
2
</sup>
now this is a different section
<p></p>
how do we keep this separate
<sup class="footnote" value='fn2'>
[x]
</sup>
# ****************************** ending here
<sup class="v" id="23">
3
</sup>
this is yet another different section
<p></p>
how do we keep this separate too
<sup class="footnote" value='fn3'>
[r]
</sup>
【问题讨论】:
标签: ruby-on-rails ruby xpath nokogiri