如何在python中解析以下内容以获取<p>
括号但没有<mark>
标记或值的文本?最好使用ElementTree功能
<plist>
<p>Hello there? <mark type="ph"/> How are you?</p>
</plist>
解析以下内容应该返回'你好吗?你好吗?
谢谢!
答案 0 :(得分:0)
如果是lxml.etree
,您可以使用string()
XPath函数:
from lxml.etree import fromstring
data = """
<plist>
<p>Hello there? <mark type="ph"/> How are you?</p>
</plist>
"""
root = fromstring(data)
for p in root.xpath("//plist/p"):
print p.xpath("string()")
打印:
Hello there? How are you?