예제 #1
0
    def from_crawler(cls, crawler):
        if crawler.settings['XMQ_ACCESS_TOKEN'] and crawler.settings['XMQ_USER_AGENT']:
            cls.TOKEN = crawler.settings['XMQ_ACCESS_TOKEN']
            cls.USER_AGENT = crawler.settings['XMQ_USER_AGENT']
        else:
            cls.TOKEN, cls.USER_AGENT = XmqApi.get_authorization()

        return cls()
예제 #2
0
 def process_response(self, request, response, spider):
     if isinstance(response, XmqApiResponse) and response.code == 401:
         spider.logger.warn('access_token(%s)已失效: %r' % (self.TOKEN, response.body))
         AuthorizationMiddleware.TOKEN, AuthorizationMiddleware.USER_AGENT = XmqApi.get_authorization()
         return request
     return response