硒无法识别路径

时间:2020-04-29 07:50:25

标签: python selenium google-chrome selenium-webdriver

Windows 10并使用Windows Subsystem for Linux。我已经从官方网站安装了适用于Windows的chromedriver。 Chrome的版本与chromedriver的版本匹配。我正在尝试使用Selenium进行网络爬虫,并在使用以下代码时进行:

driver = webdriver.Chrome(executable_path=r'C:\Users\Tyrone\Desktop\data\chromedriver.exe')

我明白了

selenium.common.exceptions.WebDriverException: Message: 'C:\Users\Tyrone\Desktop\data\chromedriver.exe' executable needs to be in PATH. 

从另一个线程(selenium - chromedriver executable needs to be in PATH)使用此代码

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())

此错误消息的结果:

/bin/sh: 1: google-chrome: not found
Traceback (most recent call last):
  File "test.py", line 5, in <module>
    driver = webdriver.Chrome(ChromeDriverManager().install())
  File "/home/w/.local/lib/python3.6/site-packages/webdriver_manager/chrome.py", line 27, in install
    driver_path = self.download_driver(self.driver)
  File "/home/w/.local/lib/python3.6/site-packages/webdriver_manager/manager.py", line 32, in download_driver
    driver_version, is_latest = self.__get_version_to_download(driver)
  File "/home/w/.local/lib/python3.6/site-packages/webdriver_manager/manager.py", line 23, in __get_version_to_download
    return self.__get_latest_driver_version(driver), True
  File "/home/w/.local/lib/python3.6/site-packages/webdriver_manager/manager.py", line 17, in __get_latest_driver_version
    return driver.get_latest_release_version()
  File "/home/w/.local/lib/python3.6/site-packages/webdriver_manager/driver.py", line 58, in get_latest_release_version
    self._latest_release_url + '_' + chrome_version(self.chrome_type))
  File "/home/w/.local/lib/python3.6/site-packages/webdriver_manager/utils.py", line 110, in chrome_version
    .format(cmd)
ValueError: Could not get version for Chrome with this command: google-chrome --version

有什么线索吗?

1 个答案:

答案 0 :(得分:0)

似乎在chromedriver中找不到path

您可以尝试将chromedriver放置在代码运行的相同路径中,然后使用以下内容

driver = webdriver.Chrome('chromedriver.exe')