无法安装 selenium webdriver 管理器

Cant install selenium webdriver manager

提问人:Togrul Kazimov 提问时间:11/10/2023 更新时间:11/16/2023 访问量:86

问:

我像往常一样尝试以下代码来安装 chrom -windows 的 selenium webdriver,但出现属性错误。我找不到类似的问题发生在其他人身上。

输入:

# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

预期输出:安装驱动程序

输出:


      3 from selenium.webdriver.chrome.service import Service as ChromeService
      4 from webdriver_manager.chrome import ChromeDriverManager
----> 6 driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

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

File c:\Users\Togrul Kazimov\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\core\manager.py:40, in DriverManager._get_driver_binary_path(self, driver)
     37     return binary_path
     39 os_type = self.get_os_type()
---> 40 file = self._download_manager.download_file(driver.get_driver_download_url(os_type))
     41 binary_path = self._cache_manager.save_file_to_cache(driver, file)
     42 return binary_path

File c:\Users\Togrul Kazimov\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\drivers\chrome.py:32, in ChromeDriver.get_driver_download_url(self, os_type)
     31 def get_driver_download_url(self, os_type):
---> 32     driver_version_to_download = self.get_driver_version_to_download()
     33     # For Mac ARM CPUs after version 106.0.5249.61 the format of OS type changed
     34     # to more unified "mac_arm64". For newer versions, it'll be "mac_arm64"
     35     # by default, for lower versions we replace "mac_arm64" to old format - "mac64_m1".
     36     if version.parse(driver_version_to_download) < version.parse("106.0.5249.61"):

File c:\Users\Togrul Kazimov\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\core\driver.py:48, in Driver.get_driver_version_to_download(self)
     45 if self._driver_version_to_download:
     46     return self._driver_version_to_download
---> 48 return self.get_latest_release_version()

File c:\Users\Togrul Kazimov\AppData\Local\Programs\Python\Python311\Lib\site-packages\webdriver_manager\drivers\chrome.py:64, in ChromeDriver.get_latest_release_version(self)
     62     return determined_browser_version
     63 # Remove the build version (the last segment) from determined_browser_version for version < 113
---> 64 determined_browser_version = ".".join(determined_browser_version.split(".")[:3])
     65 latest_release_url = (
     66     self._latest_release_url
     67     if (determined_browser_version is None)
     68     else f"{self._latest_release_url}_{determined_browser_version}"
     69 )
     70 resp = self._http_client.get(url=latest_release_url)

AttributeError: 'NoneType' object has no attribute 'split'
python 硒 webdriver selenium-chromedriver web驱动程序

评论


答:

0赞 drkat 11/16/2023 #1

我也遇到了这个问题。鉴于此 PR,这似乎是一个已知问题。 解决方法是指定应下载的版本。从软件包的网站

from webdriver_manager.chrome import ChromeDriverManager

ChromeDriverManager(driver_version="2.26").install()

我查看了源代码,最新的 Chrome 版本可以在这里找到。更全面的版本列表在这里

所以,对你来说,这可能是:

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

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(driver_version="2.26").install()))

评论

0赞 Togrul Kazimov 11/24/2023
谢谢。但不幸的是,它没有奏效。它抛出以下错误: ErrorHandler.check_response(self, response) 227 alert_text = value[“alert”].get(“text”) 228 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy 在这里不够聪明 --> 229 raise exception_class(message, screen, stacktrace) WebDriverException: Message: unknown error: cannot find dict 'desiredCapabilities' (Driver info: chromedriver=2.26.436362 (5476ec6bf7ccbada1734a0cdec7d570bb042aa30),platform=Windows NT 10.0.22621 x86_44 千米赛