发现报错“UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1:invalid start byte”,

方法一:

根据报错提示,错误原因有一条是这样的:

“'Accept-Encoding': 'gzip, deflate'”

网络上的解释是: 

这句话的意思是本地接收压缩格式的数据,服务器传过来压缩格式gzip的文件,而解压这种gzip文件只能用deflate算法,浏览器能够自动解压,程序却不能自动解压gzip。

总结:写爬虫程序时候还是不要写'Accept-Encoding': 'gzip, deflate'了,就让服务器传原始文件过来吧,不用压缩了。

方法二:

利用gzip进行解压缩。

python3 :

import gzip
import urllib.request
response_1 = urllib.request.urlopen('').read()
data=gzip.decompress(response_1).decode("utf-8")