The Vishal example, no matter how great it is, is confusing when it comes to the file name, and I see no reason to redefine "zipfile".
Here is my example that downloads a zip file containing several files, one of which is a csv file, which I later read in the DataFrame panda:
from StringIO import StringIO from zipfile import ZipFile from urllib import urlopen import pandas url = urlopen("https://www.federalreserve.gov/apps/mdrm/pdf/MDRM.zip") zf = ZipFile(StringIO(url.read())) for item in zf.namelist(): print("File in zip: "+ item)
(Note I am using Python 2.7.13)
This is the exact solution that worked for me. I just tweaked it a bit for Python 3 by removing StringIO and adding the IO library
Python Version 3
from io import BytesIO from zipfile import ZipFile import pandas import requests url = "https://www.nseindia.com/content/indices/mcwb_jun19.zip" content = requests.get(url) zf = ZipFile(BytesIO(content.content)) for item in zf.namelist(): print("File in zip: "+ item)
Martien Lubberink Oct. 10 '17 at 21:35 2017-10-10 21:35
source share