1.土法:
curl -o '+cid+'.xml --compressed http://comment.bilibili.tv/'+cid+'.xml
然后Readline。
2.正经办法:
import urllib2
response = urllib2.urlopen('http://www.baidu.com/')
html = response.read()
print html3.带gzip正经办法:
from StringIO import StringIO
import gzip
request = urllib2.Request('http://outofmemory.cn/')
request.add_header('Accept-encoding', 'gzip')
response = urllib2.urlopen(request)
if response.info().get('Content-Encoding') == 'gzip':
buf = StringIO( response.read())
f = gzip.GzipFile(fileobj=buf)
data = f.read()