Şık Bir Örümcek

Python ile Web Scraping

Thomas Laetsch

Data Scientist, NYU

Örümceğiniz

import scrapy
from scrapy.crawler import CrawlerProcess

class SpiderClassName(scrapy.Spider):
    name = "spider_name"
    # the code for your spider
    ...

process = CrawlerProcess()

process.crawl(SpiderClassName)

process.start()
Python ile Web Scraping

Örümceğiniz

  • Gerekli içe aktarmalar
import scrapy
from scrapy.crawler import CrawlerProcess
  • Odaklanacağımız kısım: gerçek örümcek
class SpiderClassName(scrapy.Spider):
    name = "spider_name"
    # the code for your spider
    ...
  • Örümceği çalıştırma
# initiate a CrawlerProcess
process = CrawlerProcess()

# tell the process which spider to use
process.crawl(YourSpider)

# start the crawling process
process.start()
Python ile Web Scraping

Ağı Örmek

class DCspider( scrapy.Spider ):

    name = 'dc_spider'

    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 )
  • start_requests adlı bir fonksiyon olmalı
  • HTML’yi işlemek için en az bir ayrıştırıcı (parser) fonksiyonu olmalı
Python ile Web Scraping

Ağı Birlikte Örelim

Python ile Web Scraping

Preparing Video For Download...