【问题标题】:Chrome WebDriverException using selenium使用硒的 Chrome WebDriverException
【发布时间】:2021-08-26 07:51:52
【问题描述】:

在你给我打分之前,我必须说我阅读了这个网站上几乎所有关于谁遇到了我同样的问题的答案,但我没有找到答案。

例如 there 提出问题的人接受了第一个答案,但在答案中复制粘贴代码时出现了相同的错误。

另一个示例there 链接到this video,它没有解释太多,但没有引发错误,而不是我从视频中复制的代码。 (他不写.exe,所以他的代码中可能也会发现错误)

This one 有完全相同的问题,所以它会很完美,但没有答案被接受。

这是错误的最后一行:

selenium.common.exceptions.WebDriverException: Message: 'chrome.exe %s' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

在异常消息的末尾有一个link,表示他们已迁移到另一个站点。

这里的错误信息:

FileNotFoundError: [WinError 2] Impossibile trovare il file specificato

During handling of the above exception, another exception occurred:

#Something else beetwen

selenium.common.exceptions.WebDriverException: Message: 'chrome.exe %s' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

这是我的代码的开头:

from selenium import webdriver

chrome_path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"

driver = webdriver.Chrome(executable_path=chrome_path)

我确定路径是正确的,因为我是从 chrome.exe 属性中复制粘贴的。

我也尝试过不使用 %s,但它引发了不同的错误:

selenium.common.exceptions.WebDriverException: Message: Service C:/Program Files (x86)/Google/Chrome/Application/chrome.exe unexpectedly exited. Status code was: 0

谁能帮我解释一下怎么回事?

谢谢


编辑

我用文件资源管理器搜索“chromedriver”,没有找到。

【问题讨论】:

    标签: python-3.x selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    你可以尝试如下

    driver = webdriver.Chrome(executable_path=r'Path_to_chrome_Driver\\chromedriver.exe')
    

    您正在定位 chrome 浏览器的 exe 位置。请下载 selenium 的 chrome 驱动程序Chromedriver。然后输入chrome驱动位置。

    注意:确保您已根据您的 chrome 浏览器版本下载正确的 chromedriver。

    【讨论】:

    • chrome_path = r"C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s" driver = webdriver.Chrome(executable_path = chrome_path) 不是一回事吗?
    • 没有。您正在使用 Chrome 浏览器 exe 文件。请下载硒的 chrome 驱动程序。放在一个位置。然后在executable_path=r'Path_to_chrome_Driver\\chromedriver.exe'中输入位置
    • 好的,我找到了,没有Win 64x版本,我下载32x一个
    • 您可以从这里下载。 chromedriver.chromium.org/downloads
    • 非常感谢它的工作,我不知道必须安装 chromedriver。
    【解决方案2】:

    我看到你的路径是 Chrome(浏览器)exe 文件,而不是 Selenium 使用的 chromedriver.exe

    【讨论】:

    • C:/Program Files (x86)/Google/Chrome/Application/chrome.exe C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s C:/Program文件 (x86)/Google/Chrome/Application/chromedriver.exe C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s /Program Files (x86)/Google/Chrome/Application/chrome.exe /Program Files (x86)/Google/Chrome/Application/chrome.exe %s 所有这些都行不通
    • 那里有 chromedriver.exe 文件吗?
    • 我那里只有 chrome.exe 文件...我的电脑上没有名为 chromedriver 的文件,这很奇怪,因为我使用 chrome 作为主浏览器几个月...
    • chrome.exe 是浏览器文件。 Selenium 不是弓箭手。您需要 chromedriver.exe 才能通过 chrome 浏览器使用 Selenium
    猜你喜欢
    • 2020-04-19
    • 2018-06-08
    相关资源
    最近更新 更多