2 つの HTML コメント間でコンテンツを選択しようとしていますが、うまくいきません (「 2 つの HTML コメント間で XPath を選択するには?」を参照)。同じ行に新しいコメントがある場合に問題があるようです。
私の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>