سؤال

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?

هل كانت مفيدة؟

المحلول

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')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top