首页 > 解决方案 > 铬浏览器意外退出(Ubuntu 服务器)

问题描述

我似乎无法让 Chromedriver 与 Ubuntu 一起使用。我在 AWS (EC2) 上运行 Ubuntu。我查了一下/usr/bin,发现里面有以下包:

chromedriver               
chromium-browser

所以,我的代码如下:

options = Options()
options.binary_location = '/usr/bin/chromium-browser'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--remote-debugging-port=9222")

driver = webdriver.Chrome(executable_path='/usr/bin/chromium-browser', chrome_options=options)

而且,我收到以下错误:

    Traceback (most recent call last):
  File "test.py", line 40, in <module>
    driver = webdriver.Chrome(executable_path='/usr/bin/chromium-browser', chrome_options=options)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
    % (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/chromium-browser unexpectedly exited. Status code was: 1

如果我检查我当前的 Chrome 浏览器版本,我发现我使用的是 78.0.3904.70 版本。我使用的驱动程序是否可能已过期?

我也想知道:chromium-browser 和 Chromedriver 有什么区别?我过去曾使用 Chromedriver 登录 Chrome 以与 Selenium 一起使用。

标签: pythongoogle-chromeubuntuamazon-ec2selenium-chromedriver

解决方案


您需要将可执行路径设置为,chromedriver因为这是selenium使用的。所以那行代码需要是:

driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver', chrome_options=options) 

推荐阅读