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

相关文章:

  • 2021-08-27
  • 2021-08-25
  • 2021-12-22
  • 2022-02-15
  • 2022-12-23
  • 2021-11-17
  • 2021-08-23
  • 2021-09-07
猜你喜欢
  • 2022-12-23
  • 2021-07-31
  • 2022-01-23
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案