Skip to content

Instantly share code, notes, and snippets.

@hantoine
Last active October 27, 2024 04:10
Show Gist options
  • 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