0

私は次の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()

これもうまくいきませんでした。

4

1 に答える 1

2

この式は、関心のあるテキストノードを返します。

//div[@id="content"]/*[not(self::p and position() > last() - 2)]//text()

*あなたは後を逃していました/

于 2013-01-31T08:42:55.730 に答える