开发者

How to match a case insensitive value with XPath

开发者 https://www.devze.com 2023-02-03 01:02 出处:网络
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:

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 n开发者_C百科ame="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?


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')
0

精彩评论

暂无评论...
验证码 换一张
取 消