码迷,mamicode.com
首页 > 其他好文 > 详细

requests模块中返回的content和text的区别

时间:2020-03-01 18:24:44      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:utf8   ons   指定   http   style   unicode   request   修改编码   类型   

test

类型:str

解码类型:根据HTTP头部响应的编码做出有根据的推测,推测的文本编码。

改变编码的方式:response.encoding=gbk

用途:response.text返回的是Unicode型数据;一般用来获取文本response.text

 

 

content

类型:bytes

解码类型:没有指定

修改编码的方式:response.content.decode(utf8)

用途:response.content返回的是bytes类型,也就是二进制数据;用来获取图片,文件response.content

 

requests模块中返回的content和text的区别

标签:utf8   ons   指定   http   style   unicode   request   修改编码   类型   

原文地址:https://www.cnblogs.com/lslin/p/12391129.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!