I have an XPath with which I'm trying to match meta tags that have a name attribute with a value that contains the word 'keyword' irrespective of case. Basically, I'm trying to match:
<meta name="KEYWORDS">
<meta name="Keywords">
<meta name="keywords">
with the XPath
'descendant::meta[contains(lower-case(@name), "keyword")]/@content'
I'm using Scrapy and it's built-in Selectors, but when I try this XPath, I get an error "Invalid XPath:...". What am I doing wrong and what's the right way to do what I want?
XPath/XQuery upper-case function.
No, Chrome uses XPath 1.0.
Scrapy Selectors are built over the libxml2 library, which, AFAIK, doesn't support XPath 2.0. At least libxslt does not for sure.
You can use XPath 1.0 translate() to solve this. In general it will look like:
translate(yourString,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'abcdefghijklmnopqrstuvwxyz')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With