Coder Social home page Coder Social logo

easygospider's Introduction

Hello. Is there anybody in there 👋

OS:ArchLinux IDE:Vim WM:i3wm Gist.GitHub:karmenzind

easygospider's People

Contributors

karmenzind avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

easygospider's Issues

看你博客过来的,想问scrapy里面重写RetryMiddleware的问题

只要值settings里面设置了retry_times的次数后,直到次数用完才会执行process_exception函数去删除代理,之后再次重新请求的时候,由于重试次数已经达到了限制,爬虫会整个停掉。所以想问,应该怎么写合适一点。具体代码如下,谢谢了

def delete_proxy(self, proxy):
    if proxy:
        res = requests.get(self.url.format(proxy.replace('https://', '').replace('http://', '')))
        if 'success' in res.text:
            self.logger.info('成功删除代理{}'.format(proxy))
        else:
            self.logger.info('代理删除失败:{}'.format(proxy))

def process_response(self, request, response, spider):
    if request.meta.get('dont_retry', False):
        return response
    if response.status in self.retry_http_codes:
        reason = response_status_message(response.status)
        # 删除该代理
        self.delete_proxy(request.meta.get('proxy', False))
        return self._retry(request, reason, spider) or response
    return response

def process_exception(self, request, exception, spider):
    if isinstance(exception, self.EXCEPTIONS_TO_RETRY) \
            and not request.meta.get('dont_retry', False):
        # 删除该代理
        self.delete_proxy(request.meta.get('proxy', False))

        return self._retry(request, exception, spider)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.