解决网页抓取乱码问题

解决:
导入gzip解压方法
import urllib.request
from io import BytesIO
import gzip

url = 'http://www.mzitu.com'
response = urllib.request.urlopen(url)
html = response.read()
print(html)
buff = BytesIO(html)
f = gzip.GzipFile(fileobj=buff)
res = f.read().decode('utf-8')

print(res)

  

posted @ 2019-12-16 13:03  疯陈演义  阅读(541)  评论(0编辑  收藏  举报