首页 > 代码库 > python gzip压缩

python gzip压缩

 1 import urllib2
 2 from StringIO import StringIO
 3 import gzip
 4  
 5 def loadData(url):
 6     request = urllib2.Request(url)
 7     request.add_header(‘Accept-encoding‘, ‘gzip‘)
 8     response = urllib2.urlopen(request)
 9     if response.info().get(‘Content-Encoding‘) == ‘gzip‘:
10         print ‘gzip enabled‘
11         buf = StringIO(response.read())
12         f = gzip.GzipFile(fileobj=buf)
13         data = http://www.mamicode.com/f.read()>

python gzip压缩