【发布时间】:2015-03-19 14:13:15
【问题描述】:
在这种情况下如何获取 p 标签文本“Blahblah”:
当p标签文本字段在强标签后面时,lxml无法识别。
<p class="user_p"><strong>cc</strong>Blahblah</p>
====代码====
from lxml import html
content="""
<div>
<p class="user_p">Blahblah<strong>cc</strong></p>
<p class="user_p"><strong>cc</strong>Blahblah</p>
</div>
"""
tree = html.fromstring(content.decode('utf-8'))
p = tree.xpath('//div/p')
print p[0].text
print p[1].text
====输出====
Blahblah
None
【问题讨论】: