我想要做的是:
for element in root.xpath('//a[@id="hypProduct_[0-9]+"]'):
如何在xpath元素选择器(lxml)内使用[0-9]+?文档中说明:
By default, XPath supports regular expressions in the EXSLT namespace:
>>> regexpNS = "http://exslt.org/regular-expressions"
>>> find = etree.XPath("//*[re:test(., '^abc$', 'i')]",
... namespaces={'re':regexpNS})
>>> root = etree.XML("<root><a>aB</a><b>aBc</b></root>")
>>> print(find(root)[0].text)
aBc
You can disable this with the boolean keyword argument regexp which defaults to True.
我不太理解 ":test" 的意思。能否有人结合文档内容进行解释一下?
re:test
指定了测试函数所在的命名空间。 - user621819