在某些情况下来说,response.text 与 response.content 都是来获取response中的数据信息,效果看起来差不多。那么response.text 和 response.content 到底有哪些差别 ? 什么情况下该用 response.text 什么情况下该用 response.content ?

  • 返回的数据类型
    response.text 返回的是一个 unicode 型的文本数据
    response.content 返回的是 bytes 型的二进制数据
    也就是说如果想取文本数据可以通过response.text 如果想取图片,文件,则可以通过 response.content

  • 数据编码
    response.content 返回的是二进制响应内容
    response.text 则是默认”iso-8859-1”编码,服务器不指定的话是根据网页的响应来猜测编码。
    response.text 与 response.content

相关文章:

  • 2021-09-28
  • 2022-12-23
  • 2021-06-22
  • 2021-05-25
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2022-01-19
  • 2022-03-09
  • 2022-12-23
相关资源
相似解决方案