我有以下html文本:
<div>
<p>
"Text one"
<br>
"Text two"
<br>
"Text three"
<br>
"Text four"
</p>
</div>
我只需要使用xpath选择“文本2”和“文本3”。到目前为止,我有以下xpath可以选择整个文本:
text = doc.xpath('/div/p/text()')
尽管我希望结果是:
Text two
Text three
我该如何实现?
假设树中文本的位置决定了目标,请尝试将xpath表达式更改为
//div/p/text()[position()> 1 and position() < 4]