1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| @staticmethod def determin_chrome_driver():
chrome_path = r'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
folder_path = os.path.join(ROOT_DIR, "env_setting") file_name = 'chromedriver.exe' file_path = os.path.join(folder_path, file_name)
if os.path.exists(file_path): result = subprocess.run([file_path, '--version'], capture_output=True, text=True) driverversion = '.'.join(result.stdout.strip().split(' ')[1].split('.')[:-1])
command = f'wmic datafile where name="{chrome_path}" get Version /value' result_a = subprocess.run(command, capture_output=True, text=True, shell=True) output = result_a.stdout.strip() chromeversion = '.'.join(output.split('=')[1].split('.')[0:3])
if driverversion != chromeversion: download_driver_path = ChromeDriverManager().install() shutil.copy(download_driver_path, folder_path) else: print("版本一致,无需重新下载!")
else: download_driver_path = ChromeDriverManager().install() shutil.copy(download_driver_path, folder_path)
return file_path
|