【发布时间】:2013-04-17 02:47:53
【问题描述】:
在我的项目中,我需要使用 lxml.etree 解析 XML 文档。我是 Python 的新手,所以我不明白如何找到带有某个标签的所有类别。让我们更准确地描述它。
我有一个类似的 XML:
<cinema>
<name>BestCinema</name>
<films>
<categories>
<category>Action</category>
<category>Thriller</category>
<category>Soap opera</category>
</categories>
</films>
</cinema>
现在我需要获取所有类别的列表。在这种情况下,它将是:
<category>Action</category>
<category>Thriller</category>
<category>Soap opera</category>
我需要使用:
tree = etree.parse(file)
谢谢,欢迎任何帮助。
【问题讨论】:
标签: python-3.x lxml