还有下一个区 block
<div class="text">
<h1>head1</h1>
Text1 <br/><br/> text12 <br/><br/> text 13
<h1>head11</h1>
Text11
<h3>head3</h3>
Text2
</div>
如何在第一个 H1 后使用忽略获取文本 <br/><br/>
作为
Text1 text12 text 13
我使用 Grab Python page = g.doc.select('//div[@class="text"]/h3[1]/following-sibling::text()]') 结果是
Text1 text12 text 13 Text11 Text2
最佳答案
您可以尝试选择只有一个 h1
sibling 的 text()
...
//div[@class='text']/text()[count(preceding-sibling::h1)=1]
另一种选择是尝试使用 Kayessian 方法...
//div[@class='text']/h1[1]/following-sibling::text()[count(.|//div[@class='text']/h1[1+1]/preceding-sibling::text()) = count(//div[@class='text']/h1[1+1]/preceding-sibling::text())]
关于python - Xpath 在第一个 html 标记后获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45511841/