我有一些 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()[(preceding::dd)][某个整数]
或者
//text()[(preceding::dd)][last()]
但这一切现在都对我有用,因为带有“foo”的div计数- 未定义。我需要一些 xpath,例如 //dl/text() 但返回 'dl' 的直接祖先,没有更深的层次。