UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte

UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte_第1张图片

上面这段代码会报:UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte sequence

UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position 29802: illegal multibyte_第2张图片

错误的原因是with没有指定编码格式。指定为utf-8格式就好了。

with open('header.html', "w", encoding="utf-8")as f:

 

你可能感兴趣的:(爬虫错误集)