有人知道如何从网站上自动下载正确的 chromedriver 吗?如果没有,我会想出一个代码来下载 zip 文件并将其解压缩到临时.谢谢! 解决方案 这里是另一个解决方案,webdriver_manager 不支持.此脚本将下载最新的 chrome 驱动程序版本.导入请求导入 wget导入压缩文件导入操作系统# 获取最新的chrome驱动版本号url = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'响应 = requests.get(url)version_number = response.text# 构建下载地址download_url = "https://chromedriver.storage.googleapis.com/" + version_number +"/chromedriver_win32.zip"# 使用上面构建的 url 下载 zip 文件latest_driver_zip = wget.download(download_url,'chromedriver.zip')# 解压压缩文件使用 zipfile.ZipFile(latest_driver_zip, 'r') 作为 zip_ref:zip_ref.extractall() #这里可以指定目标文件夹路径# 删除上面下载的zip文件os.remove(latest_driver_zip)Unfortunately, Chromedriver always is version-specific to the Chrome version you have installed.So when you pack your python code AND a chromedriver via PyInstaller in a deployable .exe-file for Windows, it will not work in most cases as you won't be able to have all chromedriver versions in the .exe-file.Anyone knows a way on how to download the correct chromedriver from the website automatically?If not, I'll come up with a code to download the zip-file and unpack it to temp.Thanks! 解决方案 Here is the other solution, where webdriver_manager does not support. This script will get the latest chrome driver version downloaded.import requestsimport wgetimport zipfileimport os# get the latest chrome driver version numberurl = 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE'response = requests.get(url)version_number = response.text# build the donwload urldownload_url = "https://chromedriver.storage.googleapis.com/" + version_number +"/chromedriver_win32.zip"# download the zip file using the url built abovelatest_driver_zip = wget.download(download_url,'chromedriver.zip')# extract the zip filewith zipfile.ZipFile(latest_driver_zip, 'r') as zip_ref: zip_ref.extractall() # you can specify the destination folder path here# delete the zip file downloaded aboveos.remove(latest_driver_zip) 这篇关于在 Python 中为 Selenium 自动下载适当的 chromedriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-26 21:27