XPathEvalError: Unregistered function for matches() in lxml

白昼怎懂夜的黑 提交于 2019-11-30 10:06:11

As mentioned in the other answer, stressing on the other part of the quoted documentation, you can use EXSLT extensions to have a regex match() function with lxml, for example :

......
ns = {"re": "http://exslt.org/regular-expressions"}
nodes = root.xpath(".//p3[re:match(.,'ABC')]//preceding::p2//p3", namespaces=ns)

how can i use XPath 2.0 functions here with lxml?

You cannot (reference):

lxml supports XPath 1.0, XSLT 1.0 and the EXSLT extensions through libxml2 and libxslt in a standards compliant way.

contains() is probably the closest you can go in this case:

.//p3[contains(., 'ABC')]//preceding::p2//p3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!