几天前,我编写了一个python程序来压缩一些Html数据并插入到数据库中。我用zlib压缩了它们。你知道吗
html = "<html><head><title>Title</title></head><body><p>Paragraph</p></body></html>"
compressed_html = str(zlib.compress(html.encode('utf-8'))).replace('b\'', '').replace('\'', '')
那么压缩的html变量是这样的
x\\x9c\\xd4\\xbd\\xfbv\\xdb\\xb6\\xb30\\xfa\\x7f\\xd6\\xfa\\xde...
今天我试着这样解压。你知道吗
html = html.encode('utf-8')
# html is retireved from database.
# html is like now b'x\\x9c\\xd4\\xbd\\xfbv\\xdb\\xb6\\xb30\\xfa\\x7f\\xd6\\xfa\\xde...'
decompressed = zlib.decompress(html)
返回一个错误
Traceback (most recent call last):
File "C:/Users/Sakith Karunasena/PycharmProjects/Twibot Repairer/main.py",
line 16, in <module>
decompressed = zlib.decompress(html)
zlib.error: Error -3 while decompressing data: incorrect header check
要压缩它,用这个
根据所需的压缩比here,级别可以在-1到9之间
要存储它:
去读吧
减压回来
相关问题 更多 >
编程相关推荐