本文整理匯總了Python中scrapy.utils.reqser.request_from_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python reqser.request_from_dict方法的具體用法?Python reqser.request_from_dict怎麽用?Python reqser.request_from_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scrapy.utils.reqser
的用法示例。
在下文中一共展示了reqser.request_from_dict方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: response_from_dict
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def response_from_dict(responsed):
respcls = load_object(responsed['cls'])
request = request_from_dict(responsed['request'])
response = respcls(
encoding=responsed['encoding'],
request=request,
url=responsed['url'],
status=responsed['status'],
headers=responsed['headers'],
body=responsed['body'],
)
response.meta.update(responsed['meta'])
return response
示例2: _decode_request
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def _decode_request(self, encoded_request):
"""Decode an request previously encoded"""
return request_from_dict(pickle.loads(encoded_request), self.spider)
示例3: _decode_request
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def _decode_request(self, encoded_request):
"""Decode a request previously encoded"""
return request_from_dict(pickle.loads(encoded_request), self.spider)
示例4: process_response
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def process_response(self, request, response, spider):
""" If we were logged out, login again and retry request.
"""
if request.meta.get('_autologin') and self.is_logout(response):
autologin_meta = request.meta['_autologin']
if isinstance(autologin_meta['request'], dict):
retryreq = request_from_dict(autologin_meta['request'], spider)
else:
retryreq = autologin_meta['request'].copy()
retryreq.dont_filter = True
logger.debug(
'Logout at %s: %s', retryreq.url, _response_cookies(response))
if self.logged_in:
# We could have already done relogin after initial logout
if any(autologin_meta['cookie_dict'].get(c['name']) !=
c['value'] for c in self.auth_cookies):
logger.debug('Request was stale, will retry %s', retryreq)
else:
self.logged_in = False
# It's better to re-login straight away
yield self._ensure_login(retryreq, spider)
logout_count = retryreq.meta['autologin_logout_count'] = (
retryreq.meta.get('autologin_logout_count', 0) + 1)
if logout_count >= self.max_logout_count:
logger.debug('Max logouts exceeded, will not retry %s',
retryreq)
raise IgnoreRequest
else:
logger.debug(
'Request caused log out (%d), still retrying %s',
logout_count, retryreq)
returnValue(retryreq)
returnValue(response)
示例5: get_next_request
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def get_next_request(self):
reqd = self._queue_requests.get()
if not reqd:
return
return request_from_dict(reqd, self._spider)
示例6: _decode_request
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def _decode_request(self, encoded_request):
"""Decode an request previously encoded"""
obj = self.serializer.loads(encoded_request)
return request_from_dict(obj, self.spider)
示例7: _decode_request
# 需要導入模塊: from scrapy.utils import reqser [as 別名]
# 或者: from scrapy.utils.reqser import request_from_dict [as 別名]
def _decode_request(self, encoded_request):
return request_from_dict(pickle.loads(encoded_request), self.spider)