0

我有一个使用 Selenium 和 Firefox 的工作 python 脚本,但是在尝试仅使用设置为驱动 Brave 的 chromedriver 运行相同的脚本时,它给出了错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /opt/brave.com/brave/brave is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

和调试日志:

DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:38723/session {"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"binary": "/opt/brave.com/brave/brave", "args": [], "extensions": []}, "browserName": "chrome", "platformName": "any"}, "firstMatch": [{}]}, "desiredCapabilities": {"goog:chromeOptions": {"binary": "/opt/brave.com/brave/brave", "args": [], "extensions": []}, "platform": "ANY", "browserName": "chrome", "version": ""}}
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1:38723
DEBUG:urllib3.connectionpool:http://127.0.0.1:38723 "POST /session HTTP/1.1" 500 318
DEBUG:selenium.webdriver.remote.remote_connection:Finished Request

但是,如果我只添加一个无头参数,脚本会执行我想要它执行的操作(减去 GUI):

from selenium import webdriver

driverPath = '/home/user/etc'
options = webdriver.ChromeOptions()
options.binary_location = '/opt/brave.com/brave/brave'
options.add_argument('--headless')
driver = webdriver.Chrome(executable_path=driverPath, options=options)

所以我想知道如何让 Brave 浏览器的 GUI 也能运行。我的驱动程序和浏览器版本是正确的。二进制路径是正确的(我认为)。

4

1 回答 1

0

我记得 Chrome headless 是在 Chrome59 中发布的。所以在你成功安装 chrome 之后,你可以尝试从 shell 命令启动 chrome 并检查它是否正确安装。

chrome \
  --headless \                   # Runs Chrome in headless mode.
  https://stackoverflow.com      # URL to open.

chrome 二进制名称可能是 chrome 或 google-chrome 或其他明喻。

于 2020-01-16T07:01:04.117 回答