Home > Software design >  Python download zip file ends in corrupted file
Python download zip file ends in corrupted file

Time:01-20

I've tried various ways to download the zip file at this location: https://www.dupageresults.gov//IL/DuPage/115972/314432/reports/summary.zip

I can't seem to get the full uncorrupted file with Requests and can't seem to find the correct answer. I've tried a .click() on the xpath as well and that doesn't give me the full file either.

I can click on it manually and get an uncorrupted file but any Python method doesn't seem to work for me. Any idea what's happening here?

clicktodownload = driver.find_element(By.XPATH, value = '//div[@]').click()

CodePudding user response:

I believe my issue was I didn't give the download enough time before I applied the next method to it which was causing a corrupt zip.

CodePudding user response:

Try using python requests as following:

import requests
import shutil

def download_file(url):
    local_filename = url.split('/')[-1]
    with requests.get(url, stream=True) as r:
        with open(local_filename, 'wb') as f:
            shutil.copyfileobj(r.raw, f)

    return local_filename

download_file("https://www.dupageresults.gov//IL/DuPage/115972/314432/reports/summary.zip")

resource

  • Related