'''
根据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
本文介绍了一种从指定URL获取网页内容的方法,并针对某些需要gzip解压缩的页面进行了处理。通过Python的urllib及gzip库实现了网页内容的读取与解码。
7492

被折叠的 条评论
为什么被折叠?



