Importing the required packages, please note that I have placed warnings as it shows a ssl error
import requests
import zipfile
import io
import warnings
warnings.filterwarnings('ignore')
File url
url = 'http://www.rad.cvm.gov.br/ENETCONSULTA/frmDownloadDocumento.aspx?CodigoInstituicao=1&NumeroSequencialDocumento=98925'
Request for the file
response = requests.get(url, verify = False, stream = True)
Creating the zip file
file = zipfile.ZipFile(io.BytesIO(response.content))
Extracting the file(note that the path is the path where you will unzip the file, in this case will unzip in the script directory in zips folder)
path = './zips'
file.extractall(path)
Code
import requests
import zipfile
import io
import warnings
warnings.filterwarnings('ignore')
url = 'http://www.rad.cvm.gov.br/ENETCONSULTA/frmDownloadDocumento.aspx?CodigoInstituicao=1&NumeroSequencialDocumento=98925'
response = requests.get(url, verify = False, stream = True)
file = zipfile.ZipFile(io.BytesIO(response.content))
path = './zips'
file.extractall(path)
Update
To save without extracting
import requests
import zipfile
import io
import warnings
warnings.filterwarnings('ignore')
url = 'http://www.rad.cvm.gov.br/ENETCONSULTA/frmDownloadDocumento.aspx?CodigoInstituicao=1&NumeroSequencialDocumento=98925'
response = requests.get(url, verify = False, stream = True)
file = zipfile.ZipFile(io.BytesIO(response.content))
name = ''.join(a for a in file.namelist() if a.endswith('itr'))[1:-4]
with open(f'{name}.zip', 'wb') as f:
for a in response.iter_content(chunk_size=128):
f.write(a)
Saul, good morning! You want to set a name arbitrarily or you want the name to be what comes by "default" in the file?
– lmonferrari
by default, thank you
– Saulo