Skip to content

Instantly share code, notes, and snippets.

@recall704
Created May 1, 2015 06:27
Show Gist options
  • Save recall704/d80a298e2af679429dd4 to your computer and use it in GitHub Desktop.
Save recall704/d80a298e2af679429dd4 to your computer and use it in GitHub Desktop.
gzip 压缩的网页解码 gbk
url = 'http://www.xxoo.com/'
req = urllib2.Request(url)
req.add_header('Accept-Encoding', 'gzip, deflate');
f = urllib2.urlopen(req, timeout=30)
html = f.read()
if html[:6] == '\x1f\x8b\x08\x00\x00\x00':
html = gzip.GzipFile(fileobj = cStringIO.StringIO(html)).read()
html.decode('gbk')
a = html.decode('gbk')
print a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment