我一直在尝试在我的scrapy项目中启用Downloader中间件,但它似乎并没有得到认可。我已经安装了一些第三方中间件,我无法判断它是否被使用。我甚至尝试卸载中间件包并运行我的代码,它运行时没有提出任何错误,说包不存在或任何因此混乱。
我的settings.py中的所有内容都正常使用,因为其他设置和参数正常显示,因为它们在settings.py中定义,但只是觉得下载中间件根本不起作用。
这是我的settings.py文件中的downloader_middleware代码
DOWNLOADER_MIDDLEWARE = {
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
'scrapy_fake_useragent.middleware.RandomUserAgentMiddleware': 110, #installed with pip
'scrapy.downloadermiddlewares.retry.RetryMiddleware': 190,
'scrapy_proxies.RandomProxy': 200, #installed with pip
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 210,
}
当我运行scrapy crawl spider时,这是我的日志:
2017-07-06 12:46:20 [scrapy.middleware] INFO: Enabled downloader middlewares:
['scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware',
'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware',
'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware',
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware',
'scrapy.downloadermiddlewares.retry.RetryMiddleware',
'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware',
'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware',
'scrapy.downloadermiddlewares.redirect.RedirectMiddleware',
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware',
'scrapy.downloadermiddlewares.stats.DownloaderStats']
看起来像downlaoder_middleware代码被忽略,因为无论我安装了其他第三方中间件,都会启用UserAgentMiddleware。
此外,我尝试在我的spider.py中使用自定义设置(自定义管道确实按预期工作)但不管我是否有自定义设置都会发生相同的事情:
custom_settings = {
'ITEM_PIPELINES': {
'someCustomPipeline': 300,
},
'DOWNLOADER_MIDDLEWARE': {
'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware': None,
'scrapy_fake_useragent.middleware.RandomUserAgentMiddleware': 110, #installed with pip
'scrapy.downloadermiddlewares.retry.RetryMiddleware': 190,
'scrapy_proxies.RandomProxy': 200, #installed with pip
'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware': 210,
}
}
答案 0 :(得分:0)
要禁用所有默认中间件,文档会说您应该在$validator = Validator::make($input, array('CardKeyCode' => 'exists:customer,CARDNO'));
if ($validator->passes()) {
$ok = CustomerMaster::insert($input);
} else {
return redirect('CustomerMaster/New')->withErrors("CardNo Already Exist!!");
}
中明确地将DOWNLOADER_MIDDLEWARES_BASE
中找到的所有中间件设置为None
。正如文档here中所说的那样?