我发现最初的学习曲线与 lxml 相比有点陡峭, 只是一些共同的任务, 例如按名称、属性抓结, 并获取其内容。这里有一个非常简单的问题 。
我有一个 XML 文件。 我想找到所有被称为 的 XML 节点。 我如何才能以 Ixml 最高效的方式做到这一点?
f = open( ./test.xml )
xml = f.read()
tree = etree.parse(StringIO(xml))
context = etree.iterparse(StringIO(xml))
# How to get all the tags with the name <Review>
reviews = tree.findall( Review ) # Something like this?
我不知道我是否应该使用 客体,xpath...
评论也欢迎我读取文件的方式, 并将其变成可解析的 lxml 对象。 谢谢 。