python爬虫 response.text 和 response.content的区别,


response.text

  • 类型:str
  • 解码类型: 根据HTTP 头部对响应的编码作出有根据的推测,推测的文本编码
  • 如何修改编码方式:response.encoding=”gbk”

 

response.content

  • 类型:bytes
  • 解码类型: 没有指定 -
  • 如何修改编码方式:response.content.deocde(“utf-8”)

 

获取网页源码的通用方式
response.content.decode()
解码方式可以根据响应头中找到Content-Type:text/html;charset=utf-8或者网页源码中content="text/html;charset=utf-8’'来决定.


相关内容

    暂无相关文章

评论关闭