Today I'm creating a Python script to find a specific version of chromedriver here. My intention is to make a request to the URL containing the specific version of chromedriver I need to download and save it to the same directory as the script. However, each time I run my code to install a file, say chromedriver_win32.zip in this folder, I end up downloading the webpage it is stored on instead of the file itself.
Here's my script:
#Get the exact folder name containing the version we need to download
chromedriverVersionUrl = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_100"
response = requests.get(chromedriverVersionUrl)
latestVersionNumber = response.text
#Target the folder of the exact version we need to download and download it!
downloadUrl = "https://chromedriver.storage.googleapis.com/index.html?path=" + latestVersionNumber + "/chromedriver_win32.zip"
#Make the request and write the response to a file
r = requests.get(downloadUrl, allow_redirects=True)
open('chromedriver.zip', 'wb').write(r.content)
Every time, chromedriver.zip ends up being a very small file that windows says is a corrupted zip file. I tried downloading the contents as a .txt file and it turned out I was just downloading the webpage.
I have tried using wget and the dload libraries to download this file in addition to requests, but they have all yielded the same result. Could someone please show me what I might be doing wrong?
source https://stackoverflow.com/questions/75803718/how-to-download-chromedriver-instead-of-webpage-with-python-requests-library
Comments
Post a Comment