Python3解决UnicodeDecodeError:'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

有两种办法:

  1. 这个时候可以选择修改字符集参数,一般这种情况出现得较多是在国标码(GBK)和utf8之间选择出现了问题。
  2. 出现异常报错是由于设置了decode()方法的第二个参数errors为严格(strict)形式造成的,因为默认就是这个参数,将其更改为ignore等即可。例如:
html.decode('utf8','ignore')


猜你喜欢

转载自blog.csdn.net/qq_40309183/article/details/80716637