0

I want to extract the tif file from a range of URL. This code works for one zip file, but if I want to extract zips in a range(1,43) it doesn't work

the error is:

BadZipFile: File is not a zip file

Could somebody help me?

print('Downloading started')
for number in range(1,3):
  url = f'https://downloadagiv.blob.core.windows.net/dhm-vlaanderen-ii-dsm-raster-1m/DHMVIIDSMRAS1m_k{number}.zip'

  req = requests.get(url)
 
# Split URL to get the file name
  filename = url.split('/')[-1]

  req = requests.get(url)
  print('Downloading Completed')

  zipfile= ZipFile(BytesIO(req.content))

  listOfFileNames = zipfile.namelist()
  for filename in listOfFileNames:
           # Check filename endswith tif
    if filename.endswith('.tif'):
               # Extract a single file from zip
      zipfile.extract(filename, '/content/gdrive/My Drive')

0 Answers0