python elementtree xpath,ElementTree XPath-根据属性选择元素

在尝试使用Python的ElementTree库中的XPathSelector特性时遇到问题。代码示例显示尝试查找所有name属性为'a'的'target'元素,但引发了预期路径分隔符错误。此问题可能由于Python版本过低导致,因为XPathSelector语法在Python2.7及以上版本才被引入。解决方案是升级到Python2.7或更高版本。
摘要由CSDN通过智能技术生成

I am having trouble using the attribute XPath Selector in ElementTree, which I should be able to do according to the Documentation

Here's some sample code

XML

Python

def parse(document):

root = et.parse(document)

for target in root.findall("//target[@name='a']"):

print target._children

I am receiving the following Exception:

expected path separator ([)

解决方案

The syntax you're trying to use is new in

Such version is shipped with Python 2.7 or higher.

If you have Python 2.6 or less you still have ElementTree 1.2.6 or less.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值