私はいくつかのHTMLコードを持っています:
<dl>
<div>
<div>foo</div>
<div>
"I need getting only this text"
<dd>
<div>foo</div>
<div>foo</div>
</dd>
<div>
<div>foo</div>
<div>
"I need getting only this text"
<dd>
<div>foo</div>
<div>foo</div>
</dd>
</dl>
したがって、必要なタグ(「foo」ではない)の前に最初のテキストのみを取得する必要があります。私は次のような構文を試しました
//text()[(先行::dd)][何らかの整数]
また
//text()[(先行::dd)][last()]
しかし、「foo」を含むdivの数が未定義であるため、すべてが機能しています。//dl/text() のような xpath が必要ですが、「dl」の直接の祖先を返します。より深いレベルはありません。