Python 3.x 如何在Python 3中使用lxml?

Python 3.x 如何在Python 3中使用lxml?,python-3.x,lxml,Python 3.x,Lxml,在我的项目中,我需要使用lxml.etree解析XML文档。我是Python的新手,所以我不明白如何找到带有标记的所有类别。让我们更准确地描述它 我有一个类似于: <cinema> <name>BestCinema</name> <films> <categories> <category>Action</category> <category>Thriller

在我的项目中,我需要使用
lxml.etree
解析XML文档。我是Python的新手,所以我不明白如何找到带有标记的所有类别。让我们更准确地描述它

我有一个类似于:

<cinema>
  <name>BestCinema</name>
  <films>
    <categories>
      <category>Action</category>
      <category>Thriller</category>
      <category>Soap opera</category>
    </categories>
  </films>
</cinema>

谢谢,欢迎提供任何帮助。

它应该简单到:

from lxml import etree
el = etree.parse('input.xml')
categories = el.xpath("//category")
print(categories)
...
你应该在地图上找到的所有其他东西

tree = etree.parse(file)
from lxml import etree
el = etree.parse('input.xml')
categories = el.xpath("//category")
print(categories)
...