我正在尝试使用提取XML文档的两个标签之间的文本值xml.etree.ElementTree
。在以下示例中,这将是值text two
和text three
。我只能提取text one
。我如何从<c>
标记中找到其他文本?
import xml.etree.ElementTree as ET
root = ET.fromstring(
"<foo><c>text one<sub>ttt</sub>text two<sub>uuu</sub>text three</c></foo>")
print root[0].text # text one
用途itertext
:
>>> z
<Element 'c' at 0x1030697d0>
>>> for i in z.itertext():
... print(i)
...
text one
ttt
text two
uuu
text three
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句