
python,抓取的网页为二进制乱码,怎么解决
1个回答
展开全部
看看你的请求头Accept-Encoding是不是设置了gzip,deflate
这样的话,返回的response是需要解压缩的
# Content-Encoding: gzip
#Content-Encoding: deflate
if("Content-Encoding" in respInfo):
if("gzip" == respInfo['Content-Encoding']):
respHtml = zlib.decompress(respHtml, 16+zlib.MAX_WBITS);
elif("deflate" == respInfo['Content-Encoding']):
respHtml = zlib.decompress(respHtml, -zlib.MAX_WBITS);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |