获取网页数据时,避免多次获取被封ip,先将获取的数据给存成文件,发现解码后存入报错了
data = respon.read().decode("utf-8")
file = open("data.html", "w")
file.write(data, encodings = "utf-8")
file.close()
Traceback (most recent call last):
file.write(data)
UnicodeEncodeError: 'gbk' codec can't encode character '\xee' in position 21865: illegal multibyte sequence
解决方案:
在setting里边指定编码为utf-8,就可以解决问题了,如下图所示。
TypeError: TextIOWrapper.write() takes no keyword arguments
解决方案:
file = open("top2.html", "w",encoding='utf-8')
错误
file = open("top2.html", "r")
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 3301: illegal multibyte sequence
解决方案:
file = open("top2.html", "r", encoding="utf-8")
记录错误用
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)