python判断网页编码的方式

以百度为例:

#python3.9.5版本
import urllib.request         #引入 urllib.request
import chardet
url = 'http://www.baidu.com'
html = urllib.request.urlopen(url).read()   #打开网页读取内容
data =chardet.detect(html)     #用chardet进行内容分析
print(data)

打印出的网页编码结果如下:
在这里插入图片描述

你可能感兴趣的:(python,python,开发语言,后端)