如何使用xml.etree.ElementTree访问标签之间的文本
问题描述:
我正在尝试使用xml.etree.ElementTree
提取XML文档的两个标签之间的文本值.在下面的示例中,这将是值text two
和text three
.我只能提取text one
.
我如何从<c>
标记中找到其他文本?
I am trying to extract the text value between two tags of an XML document with xml.etree.ElementTree
. In the following example, that would be the values text two
and text three
. I can extract only text one
.
How would I find the other texts from the <c>
tag?
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