繁体   English   中英

如何在python中解码网页响应

[英]How to decode a webpage response in python

我对gzip enecoding进行了解码,如下所示:

gzipper = gzip.GzipFile(fileobj=wepage_response)
decoded_str = str(gzipper)

现在,decoded_str看起来像这样:

<gzip 0\x82\x01\xcb\n\x01
\x00\xa0\x82\x01\xc40\x82\x01\xc0\x06\t+\x06\x01\x05\x05\x070\x01\x01\x04\x82\x0
1\xb10\x82\x01\xad0\x81\x96\xa2\x16\x04\x14J\xdd\x06\x16\x1b\xbc\xf6h\xb5v\xf5\x
81\xb6\xbbb\x1a\xbaZ\x81/\x18\x0f20140804010112Z0k0 ....>

我该怎么解释?

谢谢

您需要从gzipper实例中read()内容:

import gzip
from cStringIO import StringIO

webpage_response = '\x1f\x8b\x08\x08\xe6|\xdfS\x00\x03test.txt\x00\xcb\xc8T(\xc9H-J\xe5\x02\x00\xb6\x0b\x88\x9b\t\x00\x00\x00'
gzipper = gzip.GzipFile(fileobj=StringIO(webpage_response))
decompressed_str = gzipper.read()

>>> decompressed_str
'hi there\n'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM