[英]How do I access text between tags with xml.etree.ElementTree
我正在尝试使用xml.etree.ElementTree
提取XML文档的两个标签之间的文本值。 在以下示例中,该值为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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.