20

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() 
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

1 Answers1

31

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'
Nehal J Wani
  • 16,071
  • 3
  • 64
  • 89