使用Scrapy阻止不需要的项目打印到屏幕的方法

时间:2014-08-27 23:16:10

标签: scrapy

当您从Python Shell或命令行运行Scrapy程序时,您会在屏幕上打印项目,如下所示:

c:\Python27\webscraper2\webscraper2>scrapy crawl mrcrawl2
2014-08-28 00:12:21+0100 [scrapy] INFO: Scrapy 0.24.4 started (bot: webscraper2)
2014-08-28 00:12:21+0100 [scrapy] INFO: Optional features available: ssl, http11
2014-08-28 00:12:21+0100 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'webscraper2.spiders', 'SPIDER_MODULES': ['webscraper2.spiders'], 'BOT_NAME': 'webscraper2'}
2014-08-28 00:12:21+0100 [scrapy] INFO: Enabled extensions: LogStats, TelnetConsole, CloseSpider, WebService, CoreStats, SpiderState
2014-08-28 00:12:21+0100 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddle
ware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats
2014-08-28 00:12:21+0100 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware
2014-08-28 00:12:21+0100 [scrapy] INFO: Enabled item pipelines:
2014-08-28 00:12:21+0100 [mrcrawl2] INFO: Spider opened
2014-08-28 00:12:21+0100 [mrcrawl2] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2014-08-28 00:12:21+0100 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023
2014-08-28 00:12:21+0100 [scrapy] DEBUG: Web service listening on 127.0.0.1:6080
2014-08-28 00:12:21+0100 [mrcrawl2] DEBUG: Crawled (200) <GET http://www.whoscored.com> (referer: None)

有没有办法禁用正在打印到屏幕上尚未从网页上删除的内容?理想情况下,如果响应不在200-300范围内,我只希望“DEBUG:Crawled”行打印到屏幕。

我曾尝试在Google上寻找答案,但我不确定要搜索什么。

由于

1 个答案:

答案 0 :(得分:4)

使用-L WARNING选项将loglevel设置为WARNING

scrapy crawl mrcrawl2 -L WARNING

只有在出现问题时才会打印消息。