使用python-scrapy框架爬取百度热搜榜,代码无报错,运行之后却爬取不到内容
运行结果无报错(截取部分):
2020-05-28 19:29:22 [scrapy.middleware] INFO: Enabled item pipelines:
['demo2.pipelines.Demo2Pipeline']
2020-05-28 19:29:22 [scrapy.core.engine] INFO: Spider opened
2020-05-28 19:29:22 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2020-05-28 19:29:22 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2020-05-28 19:29:22 [scrapy.core.engine] DEBUG: Crawled (200) <GET http://top.baidu.com/robots.txt> (referer: None)
2020-05-28 19:29:22 [scrapy.downloadermiddlewares.robotstxt] DEBUG: Forbidden by robots.txt: <GET http://top.baidu.com/buzz?b=1&fr=topindex>
2020-05-28 19:29:22 [scrapy.core.engine] INFO: Closing spider (finished)
2020-05-28 19:29:22 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
解决方法:
在settings.py中找到
将 ROBOTSTXT_OBEY = True
改为 ROBOTSTXT_OBEY = False 即可