我想使用xpath选择具有多个属性的节点
有什么办法可以解决我的问题吗?
node.xpath('.//td[@colspan=6 @class="mbw"]')
File "lxml.etree.pyx", line 1507, in lxml.etree._Element.xpath (src/lxml/lxml.etree.c:52198)
File "xpath.pxi", line 307, in lxml.etree.XPathElementEvaluator.__call__ (src/lxml/lxml.etree.c:152124)
File "xpath.pxi", line 227, in lxml.etree._XPathEvaluatorBase._handle_result (src/lxml/lxml.etree.c:151097)
File "xpath.pxi", line 212, in lxml.etree._XPathEvaluatorBase._raise_eval_error (src/lxml/lxml.etree.c:150896)
lxml.etree.XPathEvalError: Invalid predicate
最佳答案
您的 xpath 表达式缺少用于组合每个属性条件的逻辑运算符(and
或 or
),例如:
node.xpath('.//td[@colspan=6 and @class="mbw"]')
关于python-3.x - lxml 不支持 xpath 上的多个属性过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32883217/