Created
January 6, 2022 23:13
-
-
Save ubalklen/798941019d00282ec61c9ad7cd7a022c to your computer and use it in GitHub Desktop.
Update Chrome driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from os import path | |
import zipfile | |
import urllib | |
import requests | |
from win32com.client import Dispatch | |
if getattr(sys, "frozen", False): | |
script_path = path.dirname(sys.executable) | |
else: | |
script_path = path.dirname(path.abspath(__file__)) | |
chrome_path = r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" | |
parser = Dispatch("Scripting.FileSystemObject") | |
chrome_full_version = parser.GetFileVersion(chrome_path) | |
chrome_major_version = chrome_full_version.split(".")[0] | |
driver_version_url = ( | |
"https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" + chrome_major_version | |
) | |
driver_version = requests.get(driver_version_url).text | |
driver_zip_url = ( | |
"https://chromedriver.storage.googleapis.com/" | |
+ driver_version | |
+ "/chromedriver_win32.zip" | |
) | |
driver_zip_path = path.join(script_path, "chromedriver.zip") | |
urllib.request.urlretrieve(driver_zip_url, driver_zip_path) | |
with zipfile.ZipFile(driver_zip_path, "r") as f: | |
f.extract("chromedriver.exe", script_path) | |
os.remove(driver_zip_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment