'''
根据URL返回内容,有些页面可能需要gzip解压缩
'''
def getUrlContent(url):
#返回页面内容
doc = urllib.request.urlopen(url).read()
#解码
try:
html=gzip.decompress(doc).decode("utf-8")
except:
html=doc.decode("utf-8")
return html
转自:http://www.cnblogs.com/GarfieldTom/archive/2012/12/04/2802000.html