【发布时间】:2016-04-12 09:13:15
【问题描述】:
如果元素名称是 [x or y or z] 并且具有定义的属性,我想选择同一棵树中的所有元素。在 PHP 中运行的示例是:
xpath = "//*[name()='x' or name()='y' or name()='z'][descendant::w[@attrib][@attrib2='".$variable."']]";
所以我试图在 python 2.7 中编写它的等价物:
xpath = "[//*[//x or //y or //z][descendant::w[@attrib][@attrib2='".{0}."']]".format(variable)
但这对我不起作用。实际上我不知道为什么 php 代码使用 name() ?我可以并且应该在 python 中做同样的事情吗?
【问题讨论】:
-
@Epodax 我删除了 php 标签。
标签: python python-2.7 xpath lxml