爬虫开发进阶-scrapy框架 CrawlSpider

 

CrawlSpider  

CrawlSpider其实是Spider的一个子类,除了继承到Spider的特性和功能外,还派生除了其自己独有的更加强大的特性和功能。
其中最显著的功能就是”LinkExtractors链接提取器“。
Spider是所有爬虫的基类,其设计原则只是为了爬取start_url列表中网页,而从爬取到的网页中提取出的url进行继续的爬取工作使用CrawlSpider更合适。

 

1、创建项目:
    scrapy startprojet liPro
    

2、创建CrawlSpider爬虫
    cd liPro
    scrapy genspider -t crawl li www.pearvideo.com   # 主要区别是在创建时多 -t crawl参数 会在创建的爬虫脚本中直接继承CrawlSpider类

3、爬虫功能

4、启动爬虫
  cd liPro/spider
  scrapy runspider li.py --nolog

注意事项:

li.py

  1、注释爬虫脚本:allowed_domains

settings.py

  2、设置UA

  3、关闭robots遵守(学习阶段)

  4、看情况开启中间件

middlewares.py

  5、看情况添加proxy

 

  

posted @ 2018-11-02 19:07  eailoo  阅读(93)  评论(0)    收藏  举报