各个网站返回的网页编码各不相同
response = urllib.request.urlopen(req)
print(response.getheaders())
得到编码方式是gzip
(‘Content-Encoding’, ‘gzip’)
然后
import gzip
html = gzip.decompress(response.read()).decode("utf-8")
Tips:其他的编码方式处理也大同小异,不知道的话百度。
网站返回的编码方式其实和你发给服务器的head中你可接受的编码方式有关,像我head中是 ‘Accept-Encoding’: ‘gzip, deflate, br’
重点记住response.getheaders()就好了。
明天见导师,别嫌我菜QAQ