scrapy中下载中间件异常处理

示例:

def process_exception(self, request, exception, spider):
        # Called when a download handler or a process_request()
        # (from other downloader middleware) raises an exception.

        # Must either:
        # - return None: continue processing this exception
        # - return a Response object: stops process_exception() chain
        # - return a Request object: stops process_exception() chain
        print('xxxx')
        # 不允许直接改url
        # request.url='https://www.baidu.com'
        from scrapy import Request
        request=Request(url='https://www.baidu.com',callback=spider.parser)
        return request

 

posted @ 2020-08-06 22:25  耗油炒白菜  阅读(518)  评论(0编辑  收藏  举报