源码:
import urllib.request
url1 = 'http://www.mzitu.com'
response1 = urllib.request.urlopen(url1)
html1 = response1.read()
html1 = html1.decode("UTF-8")
print(html1)
错误:
Traceback (most recent call last):
File "D:/Python Practice/爬取妹子图.py", line 37, in <module>
html1 = html1.decode("UTF-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte
奇怪的是,我将URL改为'http://www.baidu.com',程序就不会报错,decode中的内容,单引号、双引号、大小写我都试过了,只要用www.mzitu.com就会报错,不知道为什么,看了该网站的编码,是utf-8没错的,
不知道是什么原因,求大神不吝赐教,小弟谢过了