如何使用xml.etree.ElementTree访问标签之间的文本 [英] How do I access text between tags with xml.etree.ElementTree

查看:202
本文介绍了如何使用xml.etree.ElementTree访问标签之间的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用xml.etree.ElementTree提取XML文档的两个标签之间的文本值.在下面的示例中,这将是值text twotext 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

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆