本文整理汇总了Python中grab.response.Response.runtime_body方法的典型用法代码示例。如果您正苦于以下问题:Python Response.runtime_body方法的具体用法?Python Response.runtime_body怎么用?Python Response.runtime_body使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grab.response.Response
的用法示例。
在下文中一共展示了Response.runtime_body方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_response
# 需要导入模块: from grab.response import Response [as 别名]
# 或者: from grab.response.Response import runtime_body [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: build_response
# 需要导入模块: from grab.response import Response [as 别名]
# 或者: from grab.response.Response import runtime_body [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