
1、二进制响应内容,以字节的形式访问请求响应体。
非文本请求:
>>>r.content
b'[{"repository":{"open_issues":0,"url":"https://github.com/...2、JSON响应内容,Requests有内置的JSON解码器,处理JSON数据。
>>>importrequests
>>>r=requests.get('https://github.com/timeline.json')
>>>r.json()
[{u'repository':{u'open_issues':0,u'url':'https://github.com/...3、可访问r的原始响应内容.raw。
如果你真的想这样做,请确保在初始请求中设置streamm=True。你可以这样做:
>>>r=requests.get('https://github.com/timeline.json',stream=True)
>>>r.raw
<requests.packages.urllib3.response.HTTPResponseobjectat0x1948>
>>>r.raw.read(10)
'\x1f\x8bx000\x00\x00\x00\x00\x00\x00\x00\;以上是python requests响应内容的三种方法,希望对大家有所帮助。更多Python学习指导:python基础教程
本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。