html编码类型赋与获取到文本

获取html编码类型:

1.使用apparent_encoding可以获得真实编码

1 >>> response.apparent_encoding 
2 'GB2312'

2.从html的meta中抽取

1 >>> requests.utils.get_encodings_from_content(response.text)
2 ['gb2312']

前戏结束,只出一招即可(随意选用):

1 # response.encoding = response.apparent_encoding
2 response.encoding = 'gb2312

 

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2022-02-19
  • 2021-12-03
  • 2021-08-11
猜你喜欢
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2021-09-06
相关资源
相似解决方案