当前位置: 首页>>代码示例>>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;未经允许,请勿转载。