Created
June 18, 2011 12:17
-
-
Save fengsi/1033041 to your computer and use it in GitHub Desktop.
my own urllib2 gzip hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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