我有一个正在运行的scrapy项目,但它是带宽密集型的,因为它试图下载大量的二进制文件(zip、tar、mp3等等)。在
我认为最好的解决方案是基于mimetype(Content-Type:)HTTP报头过滤请求。我看了看代码,发现了这个设置:
DOWNLOADER_HTTPCLIENTFACTORY = 'scrapy.core.downloader.webclient.ScrapyHTTPClientFactory'
我把它改成: DOWNLOADER_HTTPCLIENTFACTORY='myproject.WebClient.ScrapyHttpClient工厂'
在使用ScrapyHTTPPageGetter
时,以下是突出显示的编辑:
我觉得这是错误的,我需要更多的破烂友好的方式取消/删除请求后,立即确定它是不需要的mimetype。而不是等待整个数据被下载。在
编辑:
我特别问这个问题self.factory.noPage(Exception('Incorrect Content-Type'))
这是取消请求的正确方法吗。在
更新1:
我当前的设置已经使垃圾服务器崩溃,所以请不要尝试使用上面相同的代码来解决问题。在
更新2:
我建立了一个基于Apache的网站,使用以下结构进行测试:
/var/www/scrapper-test/Zend -> /var/www/scrapper-test/Zend.zip (symlink)
/var/www/scrapper-test/Zend.zip
我注意到,Scrapy丢弃了带有.zip
扩展名的,但是删除了没有.zip的扩展名,尽管它只是指向它的符号链接。在
解决方案是设置一个
Node.js
代理,并配置scray通过http_proxy
环境变量使用它。在proxy应该做的是:
403 Forbidden
错误并立即关闭请求/响应。这有助于节省时间,交通和刮擦不会崩溃。在代理代码示例
真的很管用!在
我构建这个中间件是为了排除不在正则表达式白名单中的任何响应类型:
要使用它,请将其添加到设置.py公司名称:
^{pr2}$也许已经很晚了。您可以使用Accept头来过滤要查找的数据。在
相关问题 更多 >
编程相关推荐