Skip to content

Instantly share code, notes, and snippets.

@fengsi
Created June 18, 2011 12:17
Show Gist options
  • Save fengsi/1033041 to your computer and use it in GitHub Desktop.
Save fengsi/1033041 to your computer and use it in GitHub Desktop.
my own urllib2 gzip hack
import urllib2, zlib
def get_page(url):
opener = urllib2.build_opener()
opener.addheaders = [('Accept-Encoding', 'gzip')]
data = opener.open(url).read()
try:
decompress_data = zlib.decompress(data, 16+zlib.MAX_WBITS)
except zlib.error:
return data
return decompress_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment