python3 UnicodeEncodeError: 'gbk' codec can't encode character '\uff70' in position 75267: illegal multibyte sequence

时间:2022-08-20 06:02:03

当你爬出想要的数据了,却发现中文是乱码的时候?请你计算下你内心的阴影面积 !

菊个栗子:

#!/usr/bin/env python3
# -*- coding: utf-8 -*- import io
import sys
import urllib.request def getHtml(url):
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030') # 改变标准输出的默认编码 这个 gb18030 支持 cmd
res = urllib.request.urlopen(url)
html = urllib.request.urlopen(url).read()
res.close()
return html.decode('utf-8') html = getHtml("https://tieba.baidu.com/index.html")
print(html)

需要的朋友 copy 代码跑跑看,小哥也是刚接触 python3 不久,存在不合理的地方还望大牛们指正!
希望可以帮助到你。
喜欢的朋友可以收藏,以便日后的不便之需!不要说你可以记得,万一有妹子问到,你想百度找我有那么快吗?
好了,牛逼就吹到这里了,为了150字小哥也是蛮拼的!!

详细的说明可以看下: 这篇博文