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() 

1 Answer 1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.