Day 72 Of 100DaysOfCode: CSS Locator

iamdurga

Durga Pokharel

Posted on March 10, 2021

Day 72 Of 100DaysOfCode: CSS Locator

This is my 72th day of #100DaysOfCode and #python learning. Like yesterday today also continue to learned more about web scraping in the topics text extraction, follow() method, spider, weaving the web, inspecting elements from Datacamp.

Xpath and CSS locator in python

from scrapy import Selector

# Create a selector object from a secret website
sel = Selector(  text = html)

# Select all hyperlinks of div elements belonging to class "course-block"
course_as = sel.css( 'div.course-block > a' )

# Selecting all href attributes chaining with css
hrefs_from_css = course_as.css( '::attr(href)' )

# Selecting all href attributes chaining with xpath
hrefs_from_xpath = course_as.xpath( './@href')
Enter fullscreen mode Exit fullscreen mode

Day 72 Of #100DaysOfCode and #Python
Web-scraping(CSS locator and changing and responses) From https://t.co/fBZgTteSh7Datacamp#WomenWhoCode #CodeNewbie #100DaysOfCode #beginner #DEVCommunity pic.twitter.com/yuC9PoDCMI

— Durga Pokharel (@mathdurga) March 10, 2021
💖 💪 🙅 🚩
iamdurga
Durga Pokharel

Posted on March 10, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related