How to combine case-insensitive value with XPath

I have XPath with which I am trying to match meta tags with a name attribute with a value containing the word "keyword", regardless of the case. Basically, I'm trying to match:

<meta name="KEYWORDS">
<meta name="Keywords">
<meta name="keywords">

with XPath

'descendant::meta[contains(lower-case(@name), "keyword")]/@content'

I use Scrapy and built-in selectors, but when I try to use this XPath, I get the error "Invalid XPath: ...". What am I doing wrong and how to do what I want to do right?

+3
source share
1 answer

Scrapy selectors are built using the libxml2 library, which, AFAIK, does not support XPath 2.0. At least libxslt is not sure.

You can use XPath 1.0 translate () to solve this problem. In general, it will look like this:

translate(yourString, 
          'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 
          'abcdefghijklmnopqrstuvwxyz')
+10
source

Source: https://habr.com/ru/post/1783482/


All Articles