我得到的xml的结构类似于下面的示例
[...]
<a>
<list>
<section>
<identifier root="88844433"></templateId>
<code code="6664.2" display="Relevant"></code>
<title>Section title </title>
</section>
</a>
</list>
[...]如何使用Python2.7中的xml.etree通过标识符块的根属性搜索标题栏?
发布于 2020-08-24 17:51:53
下面
import xml.etree.ElementTree as ET
xml = ''' <a>
<list>
<section>
<templateId root="12"></templateId>
<code code="6664.2" display="Relevant"></code>
<title>Section title </title>
</section>
</list>
</a>'''
root = ET.fromstring(xml)
section = root.find(".//section/templateId[@root='12']/..")
print(section.find('title').text)输出
Section titlehttps://stackoverflow.com/questions/63558315
复制相似问题