标签:
import urllib2 from StringIO import StringIO import gzip def loadData(url): request = urllib2.Request(url) request.add_header(‘Accept-encoding‘, ‘gzip‘) response = urllib2.urlopen(request) if response.info().get(‘Content-Encoding‘) == ‘gzip‘: print ‘gzip enabled‘ buf = StringIO(response.read()) f = gzip.GzipFile(fileobj=buf) data = f.read() else: data = response.read() return data
标签:
原文地址:http://www.cnblogs.com/x113/p/4709641.html