下载最新的 chromedriver 时出错

问题描述 投票:0回答:0

我使用的是 Chrome 115.0.5790.110,我使用的是 Selenium 4.10.0。

这是我的Python代码:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

这是我运行时的错误:

ValueError                                Traceback (most recent call last)
Cell In[11], line 3
      1 options = Options()
      2 options.add_argument("start-maximized")
----> 3 driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

File c:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\chrome.py:39, in ChromeDriverManager.install(self)
     38 def install(self) -> str:
---> 39     driver_path = self._get_driver_path(self.driver)
     40     os.chmod(driver_path, 0o755)
     41     return driver_path

File c:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\core\manager.py:30, in DriverManager._get_driver_path(self, driver)
     27 if binary_path:
     28     return binary_path
---> 30 file = self._download_manager.download_file(driver.get_url())
     31 binary_path = self.driver_cache.save_file_to_cache(driver, file)
     32 return binary_path

File c:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\core\download_manager.py:28, in WDMDownloadManager.download_file(self, url)
     26 def download_file(self, url: str) -> File:
     27     log(f"About to download new driver from {url}")
---> 28     response = self._http_client.get(url)
     29     return File(response)

File c:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\core\http.py:33, in WDMHttpClient.get(self, url, **kwargs)
     31 def get(self, url, **kwargs) -> Response:
     32     resp = requests.get(url=url, verify=self._ssl_verify, stream=True, **kwargs)
---> 33     self.validate_response(resp)
     34     if wdm_progress_bar():
     35         show_download_progress(resp)

File c:\Users\user1\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\core\http.py:16, in HttpClient.validate_response(resp)
     14 status_code = resp.status_code
     15 if status_code == 404:
---> 16     raise ValueError(f"There is no such driver by url {resp.url}")
     17 elif status_code == 401:
     18     raise ValueError(f"API Rate limit exceeded. You have to add GH_TOKEN!!!")

ValueError: There is no such driver by url https://chromedriver.storage.googleapis.com/115.0.5790/chromedriver_win32.zip

此脚本旨在定期运行,因此我无法指定 Chrome 版本。我启用了 Chrome 自动更新,并且我需要它始终下载最新的 chromedriver。

python selenium-webdriver chromium
© www.soinside.com 2019 - 2024. All rights reserved.