1.1 res.text
1.res.text ---> str类型将响应对象转换成str类型-->如果你的响应数据是HTML,可以用text转换为str import requests import json res1=requests.get(url='https://you.163.com/xhr/globalinfo//queryTop.json?__timestamp=1590732760431') ret1=res1.json() ret2=json.loads(res1.text) print(ret1) print(ret2) for i in ret1['data']['cateList']: print(i['name'])
1.2 res.json()
1.res.json()--->将响应对象转换为python的dict类型,形式(类json) import requests import json res2=requests.get(url='https://temp.163.com/special/00804KVA/cm_guoji.js?callback=data_callback') #将数据包中的类字典的数据转换成字典 res2=res2.text.replace('data_callback(','') #替换不需要的前缀 res2=res2.strip(')') #删除不需要的后缀 ret3=json.loads(res2) for i in ret3: print(i['title'])
1.3 res.content
1.res.content--->流形式:图片,视频 import requests import json res2=requests.get(url='https://weiliicimg6.pstatp.com/weili/sm/300927029686304782.webp') with open('123.jpg','wb') as f: #写文件 f.write(res2.content)