Skip to content

Instantly share code, notes, and snippets.

@hantoine
Last active November 22, 2023 06:25
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hantoine/c4fc70b32c2d163f604a8dc2a050d5f6 to your computer and use it in GitHub Desktop.
Save hantoine/c4fc70b32c2d163f604a8dc2a050d5f6 to your computer and use it in GitHub Desktop.
Download and extract a ZIP file in Python
from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile
def download_and_unzip(url, extract_to='.'):
http_response = urlopen(url)
zipfile = ZipFile(BytesIO(http_response.read()))
zipfile.extractall(path=extract_to)
@BradKML
Copy link

BradKML commented May 2, 2023

  1. Others have status code checks https://gist.github.com/niftycode/a747648db1b79396b8e4814946a4dba2
  2. There is a library called dload might be useful for others (albiet a bit buggy) https://github.com/x011/dload x011/dload#4

But here is a question: how do you deal with a zip file with multiple pieces of content inside?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment