अपना पार्सर चलाएँ

Python में Web Scraping

Thomas Laetsch

Data Scientist, NYU

फिर से

class DCspider( scrapy.Spider ):
    name = "dcspider"

    def start_requests( self ):
        urls = [ 'https://www.datacamp.com/courses/all' ]
        for url in urls:
            yield scrapy.Request( url = url, callback = self.parse )

    def parse( self, response ):
        # simple example: write out the html
        html_file = 'DC_courses.html'
        with open( html_file, 'wb' ) as fout:
            fout.write( response.body )
Python में Web Scraping

आप पहले से जानते हैं!

def parse( self, response ):

# input parsing code with response that you already know!
# output to a file, or...
# crawl the web!
Python में Web Scraping

DataCamp कोर्स लिंक: फ़ाइल में सेव करें

class DCspider( scrapy.Spider ):
    name = "dcspider"

    def start_requests( self ):
        urls = [ 'https://www.datacamp.com/courses/all' ]
        for url in urls:
            yield scrapy.Request( url = url, callback = self.parse )

def parse( self, response ):
links = response.css('div.course-block > a::attr(href)').extract()
filepath = 'DC_links.csv' with open( filepath, 'w' ) as f: f.writelines( [link + '/n' for link in links] )
Python में Web Scraping

DataCamp कोर्स लिंक: दोबारा पार्स करें

class DCspider( scrapy.Spider ):
    name = "dcspider"

    def start_requests( self ):
        urls = [ 'https://www.datacamp.com/courses/all' ]
        for url in urls:
            yield scrapy.Request( url = url, callback = self.parse )

def parse( self, response ):
links = response.css('div.course-block > a::attr(href)').extract()
for link in links: yield response.follow( url = link, callback = self.parse2 )
def parse2( self, response ): # parse the course sites here!
Python में Web Scraping

DataCamp वेबसाइट पर लिंक फॉलो करता एक स्पाइडर.

Python में Web Scraping

जॉनी पार्सिन'

Python में Web Scraping

Preparing Video For Download...