【发布时间】:2021-02-14 05:20:13
【问题描述】:
尽可能简单:
<state name = "foo1>
<foobar item1="something1" item2="somethingelse1" item3="usefulitem1"/>
<foobar item1="something2" item2="somethingelse2" item3="usefulitem2"/>
<state name = "foo2">
...
root = lxml.etree.parse(fileName)
path = "./*[contains(text(),'useful')]"
someElement = root.xpath(path)
我正在尝试列出所有 foobar 的列表,这些 foobar 中的某处包含一些带有“有用”文本的项目。我不断收到错误 TypeError: 'lxml.etree._ElementTree' object is not iterable
【问题讨论】:
-
仍然不是minimal reproducible example。 “XML”甚至不是格式正确的。
-
对不起,当我打开我的 XML 时,这就是我所看到的。我不知道我还能得到多少
标签: python xml xml-parsing