美文网首页
scrapy 重复下载url

scrapy 重复下载url

作者: 魔童转世 | 来源:发表于2018-09-02 22:55 被阅读0次

自定义下载中间件 重写 def _process_request(self, request, info):方法

from scrapy.utils.defer import mustbe_deferred
from scrapy.utils.request import request_fingerprint
from twisted.internet.defer import Deferred


    def _process_request(self, request, info):
        fp = request_fingerprint(request)
        cb = request.callback or (lambda _: _)
        eb = request.errback
        request.callback = None
        request.errback = None

        # Return cached result if request was already seen
        # if fp in info.downloaded:
        #     return defer_result(info.downloaded[fp]).addCallbacks(cb, eb)
        #
        # # Otherwise, wait for result
        wad = Deferred().addCallbacks(cb, eb)
        # info.waiting[fp].append(wad)
        #
        # # Check if request is downloading right now to avoid doing it twice
        # if fp in info.downloading:
        #     return wad

        # Download request checking media_to_download hook output first
        info.downloading.add(fp)
        dfd = mustbe_deferred(self.media_to_download, request, info)
        dfd.addCallback(self._check_media_to_download, request, info)
        dfd.addBoth(self._cache_result_and_execute_waiters, fp, info)
        # dfd.addErrback(lambda f: logger.error(
        #     f.value, exc_info=failure_to_exc_info(f), extra={'spider': info.spider})
        # )
        return dfd.addBoth(lambda _: wad)  # it must return wad at last

相关文章

  • scrapy 重复下载url

    自定义下载中间件 重写 def _process_request(self, request, info):方法

  • scrapy一些知识点

    1.scrapy的重复url处理 这是scrapy.Request的参数定义,其中有一个dont_filter参数...

  • Scrapy如何开启重复下载?

    Scrapy下载图片的时候,默认如果两个Url相同的话,就不会再下载第2个了。 使用下面的方法可以让Scrapy开...

  • 2017.7.3

    实现scrapy 爬取伯乐在线全部文章,修复对获取下一页url的错误 scrapy 提供了图片下载和处理的功能,即...

  • Scrapy和Requests的post请求详解

    1、scrapy框架发送post请求有两种格式 scrapy.FormRequest(url=url,formda...

  • 关于下载文件[只做记录,如有问题请斧正]

    具体需求:从网站下载文件保存文件名,本地路径,[由于去重策略使用下载url的id进行去重] scrapy down...

  • 创建第一个爬虫Scrapy

    参考Scrapy中文网 下载Scrapy 1. 在Scrapy中文网安装指导中下载 2. Scrapy官网下载 注...

  • 2019-03-30 爬虫

    1.URL管理器 防止重复抓取URL,防止循环抓取(两个URL相互指向) 实现方式image.png 2.网页下载...

  • 爬虫基本架构

    url 管理器 防重复抓取、循环抓起内存 setmysqlredis 下载器 下载html 到本地成字符串urll...

  • 爬虫url 拼接的坑

    前端设置根目录 scrapy可利用urllib 和scrapy中的response.urljoin(url) 去拼接

网友评论

      本文标题:scrapy 重复下载url

      本文链接:https://www.haomeiwen.com/subject/sbevwftx.html