Scrapy.css select an item with a specific name and attribute value

How can I use Scrapy to select the text of an element with a specific attribute name and value?

For instance,

<span property="city">Montreal</span>

I tried the following but got None

response.css('.span[property="city"]::text').extract_first() 
+4
source share
1 answer

You make a little mistake. You need to drop '.'to 'span':

In [6]: response.css('span[property="city"]::text').extract_first() 
Out[6]: u'Montreal'
+7
source

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


All Articles