本文整理汇总了Python中grab.response.Response.headers方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers方法的具体用法?Python Response.headers怎么用?Python Response.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grab.response.Response
的用法示例。
在下文中一共展示了Response.headers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_response
# 需要导入模块: from grab.response import Response [as 别名]
# 或者: from grab.response.Response import headers [as 别名]
def build_response(self, resource):
response = Response()
response.head = ''
response.code = resource.status_code
runtime_body = self.page.mainFrame().toHtml()
body = resource.reply.data
url = resource.reply.url().toString()
headers = resource.headers
cookies = self.get_cookies()
# py3 hack
if PY3K:
if isinstance(body, QByteArray):
body = body.data()
headers = decode_dict(headers)
cookies = decode_dict(cookies)
else:
runtime_body = unicode(runtime_body)
body = str(body)
url = str(url)
response.runtime_body = runtime_body.encode('utf-8')
response.body = body
response.url = url
response.parse(charset='utf-8')
response.headers = headers
response.cookies = cookies
return response
示例2: prepare_response
# 需要导入模块: from grab.response import Response [as 别名]
# 或者: from grab.response.Response import headers [as 别名]
def prepare_response(self, grab):
#self.response.head = ''.join(self.response_head_chunks)
#self.response.body = ''.join(self.response_body_chunks)
#self.response.parse()
#self.response.cookies = self._extract_cookies()
#self.response.code = self.curl.getinfo(pycurl.HTTP_CODE)
#self.response.time = self.curl.getinfo(pycurl.TOTAL_TIME)
#self.response.url = self.curl.getinfo(pycurl.EFFECTIVE_URL)
response = Response()
response.head = ''
#if grab.config['body_max_size'] is not None:
#chunks = []
#read_size = 0
#for chunk in self._requests_responsek
#else:
#response.body = self._requests_response.content
response.body = self._requests_response.content
response.code = self._requests_response.status_code
response.headers = self._requests_response.headers
response.cookies = self._requests_response.cookies or {}
response.url = grab.config['url']
if grab.config['charset'] is not None:
response.parse(charset=grab.config['charset'])
else:
response.parse()
return response
示例3: build_response
# 需要导入模块: from grab.response import Response [as 别名]
# 或者: from grab.response.Response import headers [as 别名]
def build_response(self, resource):
response = Response()
response.head = ''
response.runtime_body = unicode(self.page.mainFrame().toHtml()).encode('utf-8')
response.body = str(resource.reply.data)
response.code = resource.status_code
response.url = str(resource.reply.url().toString())
response.parse(charset='utf-8')
response.headers = resource.headers
response.cookies = self.get_cookies()
return response