1 import urllib2 2 from StringIO import StringIO 3 import gzip 4 5 def loadData(url): 6 request = urllib2.Request(url) 7 request.add_header('Accept-encoding', 'gzip') 8 response = urllib2.urlopen(request) 9 if response.info().get('Content-Encoding') == 'gzip': 10 print 'gzip enabled' 11 buf = StringIO(response.read()) 12 f = gzip.GzipFile(fileobj=buf) 13 data = f.read() 14 else: 15 data = response.read() 16 return data