Python之Scrapy遇见个坑

运行Scrapy爬虫被限制抓取,报错:

2018-01-08 18:37:14 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2018-01-08 18:37:14 [scrapy.core.engine] INFO: Spider opened
2018-01-08 18:37:14 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2018-01-08 18:37:14 [scrapy.extensions.telnet] DEBUG: Telnet console listening on 127.0.0.1:6023
2018-01-08 18:37:23 [scrapy.core.engine] DEBUG: Crawled (403) <GET https://accounts.douban.com/login> (referer: None)
2018-01-08 18:37:23 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <403 https://accounts.douban.com/login>: HTTP status code is not handled or not allowed
2018-01-08 18:37:23 [scrapy.core.engine] INFO: Closing spider (finished)
2018-01-08 18:37:23 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 222,

解决方法:

settings.py中添加用户代理

USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.54 Safari/536.5' 

搞定。。。

 

上一篇:京东 37 岁程序员加班猝死?当事人回应:我还在写代码,已报警~


下一篇:ThinkPHP学习 --- 37 路由的地址和缓存--------------38 -----------------学习