In Python, how do I decode GZIP encoding?

后端 未结 8 1752
星月不相逢
星月不相逢 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:35

    For Python 3

    Try out this:

    import gzip
    
    fetch = opener.open(request) # basically get a response object
    data = gzip.decompress(fetch.read())
    data = str(data,'utf-8')
    

提交回复
热议问题