本文介绍了路径.如何选择两个标签之间的所有文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是html源代码
<div class="text"><a name="dst100030"></a><pre id="p73" class="P"><span class="blk">│Лабораторные методы исследования │</span></pre><pre id="p74" class="P"><span class="blk">├─────────────┬───────────────────────────────┬────────────────────┬──────────────┤</span></pre><a name="dst100031"></a>
我需要获取两个 标签之间的所有文本.我试过的是
response.xpath('//pre//text()[preceding-sibling::a[@name="dst100030"] and following-sibling::a[@name="dst100031"]]')
的兄弟,而不是 text().您可以使用preceding::a
代替(对于following
也类似).Here is the html source code
<div class="text"><a name="dst100030"></a><pre id="p73" class="P"><span class="blk">│Лабораторные методы исследования │</span></pre><pre id="p74" class="P"><span class="blk">├────────────┬───────────────────────────┬─────────────────┬──────────────┤</span></pre><a name="dst100031"></a>
I need to get all text in between the two
<a name="dst100030">
tags.What i tried isresponse.xpath('//pre//text()[preceding-sibling::a[@name="dst100030"] and following-sibling::a[@name="dst100031"]]')
But it returns empty list. Where am I wrong?
解决方案
<a>
is a sibling of<pre>
, not the text(). You can usepreceding::a
instead (and similarly forfollowing
).这篇关于路径.如何选择两个标签之间的所有文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!