我在使用ElementTree的XPath选择器属性时遇到了困难,根据文档,我应该能够这样做。
下面是一些示例代码
XML
<root>
<target name="1">
<a></a>
<b></b>
</target>
<target name="2">
<a></a>
<b></b>
</target>
</root>
Python
:Python是一种高级编程语言,常被用于Web开发、数据分析、人工智能等领域。def parse(document):
root = et.parse(document)
for target in root.findall("//target[@name='a']"):
print target._children
我收到了以下异常:
expected path separator ([)
findall
仅支持XPath
的子集。请参阅此处的邮件列表讨论(https://mailman-mail5.webfaction.com/pipermail/lxml/20060526/009219.html)。 - Mike Marshall