Nyxynyx
Nyxynyx

Reputation: 63619

Scrapy .css select element with a specific attribute name and value

How can Scrapy be used to select the text of an element that has a particular attribute name and value?

For example,

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

I tried the following but received a None

response.css('.span[property="city"]::text').extract_first() 

Upvotes: 20

Views: 11486

Answers (1)

Nehal J Wani
Nehal J Wani

Reputation: 16619

You are making a small mistake. You need to drop the '.' before 'span':

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

Upvotes: 31

Related Questions