【问题标题】:Cannot find Chromium binary Linux Python Selenium [duplicate]找不到 Chromium 二进制 Linux Python Selenium [重复]
【发布时间】:2020-08-16 03:16:39
【问题描述】:

我正在尝试使用 PyCharm 使用 Selenium 打开 Chromium。 这是我的代码:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.binary_location = '/usr/bin/chromium-browser'

chrome_driver_binary = '/opt/WebDriver/bin/chromedriver'
driver = webdriver.Chrome(chrome_driver_binary, chrome_options=options)
driver.get('http://google.com/')

我在以 'driver = ' 开头的行中出现错误

selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at /usr/bin/chromium-browser

其实在/usr/bin里面有个东西叫chromium-browser,一个可执行文件。

我也从Set chrome browser binary through chromedriver in Python 尝试过这个解决方案,但没有更好的:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities.CHROME
cap = {'binary_location': '/usr/bin/chromium-browser'}
driver = webdriver.Chrome(desired_capabilities=cap, executable_path='/opt/WebDriver/bin/chromedriver')
driver.get('http://google.com/')

给予:

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

有什么帮助吗?第三个小时在谷歌上搜索它;)

【问题讨论】:

    标签: python linux selenium chromium


    【解决方案1】:

    在终端中执行which chromedriver

    我希望它会返回路径 /usr/bin/chromedriver,尽管无论返回的路径是什么,它都是用作 executable_path 的路径。

    您可能需要强制使用原始字符串,例如:

    chrome_driver_binary = r'/usr/bin/chromedriver'
    

    【讨论】:

    • 我已经完成了,但是输出是No such file or directory: '/usr/local/bin/chromedriver': '/usr/local/bin/chromedriver', 然后是'During handling在上述异常中,发生了另一个异常:' 'chromedriver' 可执行文件需要在 PATH 中。
    猜你喜欢
    • 1970-01-01
    • 2018-12-28
    • 2012-07-15
    • 1970-01-01
    • 2021-04-09
    • 2016-09-19
    • 2021-04-23
    • 2022-08-02
    • 1970-01-01
    相关资源
    最近更新 更多