无法安装selenium webdriver管理器

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

我像往常一样尝试下面的代码为 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 selenium-webdriver selenium-chromedriver webdriver
1个回答
0
投票

我也遇到这个问题了。考虑到此 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()))
© www.soinside.com 2019 - 2024. All rights reserved.