In Python, how do I decode GZIP encoding?

后端 未结 8 1736
星月不相逢
星月不相逢 2020-11-28 07:53

I downloaded a webpage in my python script. In most cases, this works fine.

However, this one had a response header: GZIP encoding, and when I tried to print the sou

8条回答
  •  温柔的废话
    2020-11-28 08:40

    I use zlib to decompress gzipped content from web.

    import zlib
    import urllib
    
    f=urllib.request.urlopen(url) 
    decompressed_data=zlib.decompress(f.read(), 16+zlib.MAX_WBITS)
    

提交回复
热议问题