创建CrawlSpider爬虫简要步骤

创建CrawlSpider爬虫简要步骤:

1. 创建项目文件:

e.g: scrapy startproject douyu (douyu为项目名自定义)

 

2. 进入项目文件:

e.g: cd douyu/  => cd douyu/ (两次)

 

3. 修改items.py文件中需要获取的字段:

e.g: vim items.py  =>  name = scrapy.Field()

 

4. 进入爬虫文件:

e.g: cd spider/

 

5. 创建爬虫:

e.g: scrapy genspider -t crawl dy 'douyu.com' (dy为爬虫名,不要和项目名一致;douyu.com为限制爬虫范围)

 

6. 修改dy.py

7. 修改管道文件pipelines.py

8. 设置settings.py

e.g: 优先级设置等

9. 运行命令:

e.g: scrapy crawl dy

 

 

注: 默认的Rules规则中,follow为True,如若跟进,可省略不写;当有callback回调函数时,不写follow,默认follow为True

 

posted @ 2018-08-21 18:33  时间&煮雨~  阅读(2086)  评论(0编辑  收藏  举报