requests中获取请求到文本编码格式


1.使用requests模块:

import requests

2.通过网络请求,并获取到数据

url = "http://www.stat-nba.com/award/item14.html"
response = requests.get(url)

3.通过获取到的请求结果,调用encoding方法即可得到文本的编码格式

print(response)
print(response.encoding)

输出结果:

<Response [200]>
ISO-8859-1

4.如果要将现在显示的编码改变成utf-8格式,通过如下操作:

response.text.encode("ISO-8859-1").decode("utf-8")

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM