In [1]:
import gzip
import urllib2
from io import BytesIO

r = urllib2.urlopen(urllib2.Request('http://stackoverflow.com', 
                    headers={'Accept-Encoding': 'gzip;q=1.0, *;q=0'}))
print r.info()
s = r.read()
print("comressed size: %d" % len(s))

f = gzip.GzipFile(fileobj=BytesIO(s))
print("uncompressed: %d" % len(f.read()))
Cache-Control: public, max-age=11
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: Thu, 13 Dec 2012 09:06:05 GMT
Last-Modified: Thu, 13 Dec 2012 09:05:05 GMT
Vary: *
Date: Thu, 13 Dec 2012 09:05:53 GMT
Connection: close
Content-Length: 44242

comressed size: 44242
uncompressed: 210410

In []:
 
Back to top