考虑如下xml
结构
<p class="long">
<i>Malicious</i>
" is the adjective based on the noun "
<i>malice</i>
", which means the desire to harm others. Both words come from the latin word "
</p>
我想选择<p>
标记内的所有文本。我尝试过
examples = tree.xpath('//p[@class="long"]/text()')
但是,由于这个<i>
原因,标签之间的所有文本都会被忽略。
提取<p>
标签内所有文本的正确方法是什么,而不管其是否也包含在其他嵌套标签中?
尝试一下
examples=tree.xpath('//p[@class="long"]//text()')
(在之前加上双斜杠text()
,它也与不是直接子级的节点匹配)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句