1

I have the following HTML structure
I want to extract all the links with the class:dev-link

<a class="dev-link" href="mailto:[email protected]" rel="nofollow" title='Photoshoot"</a> 

I am using the below code to extract the link in scrapy

response.css('.dev-link::attr(href)').extract()

I am getting the correct output but is this the right way to use css selectors??

1
  • if you are using python, why not using regex? Commented Jan 25, 2018 at 17:47

1 Answer 1

1

As you can see in Scrapy Documentation there are two methods to scrap data, CSS Selector and XPath Selector both are works correctly but XPath needs some practice to get expert, in my opinion, Xpath is more power in special cases you can scrap data easier that CSS selector ( but of course you can get them with CSS selector too),

what you did is correct

 link = response.css('.dev-link::attr(href)').extract_first()

and also you can get it with the following too

link = response.xpath('/[contains(@class,’dev-link’)]/@href').extract_first()
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.