【发布时间】:2019-11-07 15:33:54
【问题描述】:
我们可以通过一个属性获取节点:
# root is an instance of etree._Element
nodes = root.findall('person[@city="NY"]')
但是,如何获取多个属性过滤的节点?
nodes = root.findall('person[@city="NY" @gender="M"]')
这不起作用。
【问题讨论】:
我们可以通过一个属性获取节点:
# root is an instance of etree._Element
nodes = root.findall('person[@city="NY"]')
但是,如何获取多个属性过滤的节点?
nodes = root.findall('person[@city="NY" @gender="M"]')
这不起作用。
【问题讨论】:
试试这个方法:
nodes = root.findall('person[@city="NY"][@gender="M"]')
看看它是否有效。
【讨论】: