天天看點

scrapy簡單爬蟲(scrapy.Spider)與深度爬蟲(spiders.CrawlSpider)的對比

scrapy簡單爬蟲(scrapy.Spider)與深度爬蟲(spiders.CrawlSpider)的對比

1、建立方式不一樣

簡單爬蟲

scrapy genspider 爬蟲名 "限定域,如:xxx.com"
           

深度爬蟲

scrapy genspider -t crawl  爬蟲名 "限定域,如:xxx.com"
           

2、 parse()方法的作用不一樣

  • 注意:當編寫爬蟲規則時,避免使用parse作為回調函數。由于CrawlSpider使用parse方法來實作其邏輯,如果覆寫了 parse方法,crawl spider将會運作失敗。

3、回調函數調用不一樣

簡單爬蟲

callback = self.函數名
           

深度爬蟲

callback = "函數名"
           

繼續閱讀