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

 

相关文章:

  • 2021-11-27
  • 2021-12-04
  • 2022-12-23
  • 2021-08-13
  • 2021-11-27
  • 2021-07-12
  • 2021-08-29
  • 2021-12-28
猜你喜欢
  • 2021-06-01
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
相关资源
相似解决方案