Downloading compressed content over HTTP using Python

你离开我真会死。 提交于 2020-01-13 17:55:15

问题


How do I take advantage of HTTP 1.1's compression when downloading web pages using Python?

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.

Is it already built-in into urllib or is there another library that I can use?


回答1:


httplib2 supports 'deflate' and 'gzip' compression.

Example

import httplib2
h = httplib2.Http(".cache")
resp, content = h.request("http://example.org/", "GET")

The content is decompressed as necessary.



来源:https://stackoverflow.com/questions/1316517/downloading-compressed-content-over-http-using-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!