当前位置: 首页>>代码示例>>Python>>正文


Python Response.headers方法代码示例

本文整理汇总了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
开发者ID:Scaurus,项目名称:grab,代码行数:32,代码来源:__init__.py

示例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
开发者ID:Kuznitsin,项目名称:grab,代码行数:30,代码来源:requests.py

示例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
开发者ID:vasia123,项目名称:grab,代码行数:13,代码来源:__init__.py


注:本文中的grab.response.Response.headers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。