使用Scrapy采集

1、有些站点通过robot协议,防止scrapy爬取,就会出现如下问题:

 DEBUG: Forbidden by robots.txt: <GET http://baike.baidu.com/lishi/>

解决方案:settings.py 文件中:ROBOTSTXT_OBEY = False(默认为true)

2、shell中执行爬虫会看到很多乱七八糟的日志输入

3、爬虫执行日志输出到指定文件中

scrapy crawl article -s LOG_FILE=wiki.log

4、爬去结果保存为指定格式

$ scrapy crawl article -o articles.csv -t csv
$ scrapy crawl article -o articles.json -t json
$ scrapy crawl article -o articles.xml -t xml
原文地址:https://www.cnblogs.com/tianboblog/p/6993441.html