私は次のhtmlを持っています。
<div id="content">
<h3>Title</h3>
<p>Some stuff</p>
<p>other stuff</p>
<p>other other stuff</p>
<p>unnecessary stuff</p>
<p>other unnecessary stuff</p>
</div>
ここまでこの表現を書いてきました。
//div[@id="content"]//text()
<p>
これは機能しますが、最後の 2 つの要素のテキストを抽出する必要がないため、抽出したくありません。これを書いてみた...
//div[@id="content"]/p[not(position() > last() - 2)]//text()
これは期待どおりに機能しませんでした。それから私はこれを試しました...
//div[@id="content"]/[not(self::p[position() > last() - 2])]//text()
これもうまくいきませんでした。