Extracting links with specific class using css selectors

215
January 25, 2018, at 11:10 PM

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

<a class="dev-link" href="mailto:info@jourist.com" 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??

Answer 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()
Rent Charter Buses Company
READ ALSO
Python Reading from JSON accented characters coming out wrong

Python Reading from JSON accented characters coming out wrong

I have a string like this ("Theres loads of adventures to be had here;\nYou'll get your own Kobémon\nand get to catch more!") in myJSON file and when I read from it into the python file and into a Tkinter textbox I get "é" instead of é

290
Hashing Password in .py file

Hashing Password in .py file

how i said in the title, i want the password to be hashed when is savedIts possible with this?

346
use python telegram bot to send and receive messages to/from group

use python telegram bot to send and receive messages to/from group

I want to use a python telegram bot to watch messages and send or receive messages from group and process them but I couldn't find any resource for this on the Internetis there any resource to show how to use python-telegram-bot package to use a telegram...

364
How can I use sum?

How can I use sum?

On my tree view I should show the total (last line) of a specific fieldwith a float field it works with no problem but as the field is a string it doesn't

284