python爬取网页信息时出现UnicodeEncodeError

print( response.text)
UnicodeEncodeError: 'gbk' codec can't encode character '\xa9' in position 252144: illegal multibyte sequence

UnicodeEncodeError: ‘gbk’ codec can’t encode character ‘\xa9’ in position 11163: illegal multibyte sequence

此问题出现时先转码为GBK,在加上ignore参数,在解码为GBK即可解决

解决办法:

print( response.text.encode('gbk','ignore').decode('gbk'))

 

上一篇:第二十三篇英文翻译


下一篇:2.10英文题面翻译