python2报错 UnicodeDecodeError: ‘utf8′ codec can’t decode byte 0xbc in position 0: invalid start byte
这不是编码问题,是网址有压缩,下面是py2的写法
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import urllib2, StringIO, gzip s = urllib2.urlopen('http://mrdede.com/') h = s.read() #print h compressedstream = StringIO.StringIO(h) gzipper = gzip.GzipFile(fileobj=compressedstream) data = gzipper.read() print data |