【发布时间】:2013-10-29 16:17:59
【问题描述】:
我正在尝试在两个 HTML cmets 之间选择一些内容,但在正确处理时遇到了一些问题(如“XPath to select between two HTML comments?”中所示)。 当新的 cmets 在同一行时似乎有问题。
我的 HTML:
<html>
........
<!-- begin content -->
<div>some text</div>
<div>
<p>Some more elements</p>
</div>
<!-- end content --><!-- begin content -->
<div>more text</div>
<!-- end content -->
.......
</html>
我用:
doc.xpath("//node()[preceding-sibling::comment()[. = ' begin content ']]
[following-sibling::comment()[. = ' end content ']]")
结果:
<div>some text</div>
<div>
<p>Some more elements</p>
</div>
<!-- end content --><!-- begin content -->
<div>more text</div>
我想得到什么:
<div>some text</div>
<div>
<p>Some more elements</p>
</div>
【问题讨论】:
标签: html ruby xpath nokogiri scraper