當前位置: 首頁>>代碼示例>>Python>>正文


Python reqser.request_to_dict方法代碼示例

本文整理匯總了Python中scrapy.utils.reqser.request_to_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python reqser.request_to_dict方法的具體用法?Python reqser.request_to_dict怎麽用?Python reqser.request_to_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scrapy.utils.reqser的用法示例。


在下文中一共展示了reqser.request_to_dict方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: publish_links

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def publish_links(self, requests_new, urls_other):
        # Serialize requests_new
        reqds_new = []
        for request_new in requests_new:
            try:
                reqd_new = request_to_dict(request_new, self._spider)
                reqds_new.append(reqd_new)
            except ValueError as e:
                logger.error(
                    u'Unable to serialize request: %(request)s - reason: %(reason)s',
                     {'request': request_new, 'reason': e},
                     exc_info=True, extra={'spider': self._spider}
                )

        # Send to queue
        if len(urls_other) <= 0 and len(reqds_new) <= 0:
            return

        payload = {
            'requests_new': reqds_new,
            'urls_other': urls_other,
        }
        self._queue_links.publish(payload) 
開發者ID:fabienvauchelles,項目名稱:frontoxy,代碼行數:25,代碼來源:queue.py

示例2: _encode_request

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def _encode_request(self, request):
        """Encode a request object"""
        return pickle.dumps(request_to_dict(request, self.spider), protocol=-1) 
開發者ID:onecer,項目名稱:sbdspider,代碼行數:5,代碼來源:queue.py

示例3: process_request

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def process_request(self, request, spider):
        """ Login if we are not logged in yet.
        """
        if '_autologin' in request.meta or request.meta.get('skip_autologin'):
            returnValue(None)
        yield self._ensure_login(request, spider)
        self.stats.set_value('autologin/logged_in', self.logged_in)
        if self.skipped:
            request.meta['autologin_active'] = False
            returnValue(None)
        elif self.logged_in:
            request.meta['autologin_active'] = True
            logout_url = request.meta.get(
                'autologin_logout_url', self.logout_url)
            if logout_url and logout_url in request.url:
                logger.debug('Ignoring logout request %s', request.url)
                raise IgnoreRequest
            # Save original request to be able to retry it in case of logout
            req_copy = request.replace(meta=deepcopy(request.meta))
            request.meta['_autologin'] = autologin_meta = {}
            try:
                autologin_meta['request'] = request_to_dict(
                    req_copy, spider=spider)
            except ValueError:
                # Serialization failed, but it might be ok if we do not persist
                # requests, so store the request itself here.
                autologin_meta['request'] = req_copy
            # TODO - it should be possible to put auth cookies into the
            # cookiejar in process_response (but also check non-splash)
            if self.auth_cookies:
                request.cookies = self.auth_cookies
                autologin_meta['cookie_dict'] = {
                    c['name']: c['value'] for c in self.auth_cookies} 
開發者ID:TeamHG-Memex,項目名稱:autologin-middleware,代碼行數:35,代碼來源:middleware.py

示例4: retry_request

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def retry_request(self, request):
        try:
            reqd = request_to_dict(request, self._spider)
            self._queue_requests.retry(reqd, reqd['priority'])
        except ValueError as e:
            logger.error(
                u'Unable to serialize request: %(request)s - reason: %(reason)s',
                {'request': request, 'reason': e},
                exc_info=True, extra={'spider': self._spider}
            ) 
開發者ID:fabienvauchelles,項目名稱:frontoxy,代碼行數:12,代碼來源:queue.py

示例5: publish_error

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def publish_error(self, request, exception):
        error = {
            'request': request_to_dict(request, self._spider),
            'cls': self._get_exception_class(exception),
            'msg': str(exception)
        }
        self._queue_errors.publish(error) 
開發者ID:fabienvauchelles,項目名稱:frontoxy,代碼行數:9,代碼來源:queue.py

示例6: response_to_dict

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def response_to_dict(response):
    return {
        'cls': '{r.__module__}.{r.__class__.__name__}'.format(r=response),
        'encoding': response.encoding,

        'request': request_to_dict(response.request),

        'url': response.url,
        'status': response.status,
        'headers': dict(response.headers),
        'meta': response.meta,

        'body': response.body,
    } 
開發者ID:fabienvauchelles,項目名稱:frontoxy,代碼行數:16,代碼來源:utils.py

示例7: _encode_request

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def _encode_request(self, request):
        """Encode a request object"""
        obj = request_to_dict(request, self.spider)
        return self.serializer.dumps(obj) 
開發者ID:Python3WebSpider,項目名稱:ScrapyRedisBloomFilter,代碼行數:6,代碼來源:queue.py

示例8: _encode_request

# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_to_dict [as 別名]
def _encode_request(self, request):
        return pickle.dumps(request_to_dict(request, self.spider), protocol=-1) 
開發者ID:aaldaber,項目名稱:Distributed-Multi-User-Scrapy-System-with-a-Web-UI,代碼行數:4,代碼來源:queue.py


注:本文中的scrapy.utils.reqser.request_to_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。