使用Python通过HTTP下载压缩内容 [英] Downloading compressed content over HTTP using Python
本文介绍了使用Python通过HTTP下载压缩内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在使用Python下载网页时利用HTTP 1.1的压缩?
How do I take advantage of HTTP 1.1's compression when downloading web pages using Python?
我目前正在使用内置的 urllib 模块,用于下载网页内容。阅读文档后,我找不到任何确实使用压缩的信息。
I am currently using the built-in urllib module for downloading web content. Reading through the documentation I couldn't find any information that is indeed using compression.
它是否已内置于 urllib 或是否存在我可以使用另一个图书馆?
Is it already built-in into urllib or is there another library that I can use?
推荐答案
httplib2 支持'deflate'和'gzip'压缩。
httplib2 supports 'deflate' and 'gzip' compression.
示例
import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://example.org/", "GET")
根据需要解压缩内容。
The content is decompressed as necessary.
这篇关于使用Python通过HTTP下载压缩内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文