明显是gzip过的吧
def fetchHtml(url):
#url="
http://www.baidu.com/s?wd="+urllib2.quote(keyword)
try:
request = urllib2.Request(url)
request.add_header('Accept-encoding', 'gzip')
opener = urllib2.build_opener()
f = opener.open(request)
isGzip = f.headers.get('Content-Encoding')
#print isGzip
if isGzip :
compresseddata = f.read()
compressedstream = StringIO.StringIO(compresseddata)
gzipper = gzip.GzipFile(fileobj=compressedstream)
data = gzipper.read()
else:
data = f.read()
return data
except exceptions,e:
print e
#returnhtml=urllib2.urlopen(url).read()
return fetchHtml(url)