python3 抓取网页中文title乱码

1.sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') 不生效

2.re.search("(?<=charset=).*(?=\")", data)抓取网页编码,进行解码不生效

3.

r = requests.get('http://......./')

print(r.encoding) #查看编码,iso8859-1造成乱码

if r.encoding == 'ISO-8859-1':

txt = r.text.encode(r.encoding).decode('gbk')

猜你喜欢

转载自blog.csdn.net/yufanghu/article/details/79908090