【问题标题】:selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited with ChromeDriver Selenium Python on Linuxselenium.common.exceptions.WebDriverException:消息:服务 /usr/bin/google-chrome 在 Linux 上使用 ChromeDriver Selenium Python 意外退出
【发布时间】:2019-12-04 10:36:49
【问题描述】:
from selenium import webdriver

driver = webdriver.Chrome(executable_path=r'/usr/local/bin/google-chrome')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

我收到此错误:

 File "test.py", line 5, in <module>
    driver = webdriver.Chrome(executable_path=r'/usr/bin/google-chrome')
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/usr/local/python3/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
    self.assert_process_still_running()
  File "/usr/local/python3/lib/python3.6/site-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/google-chrome unexpectedly exited. Status code was: 1

我尝试了互联网上的其他解决方案,但我尝试的每个解决方案都收到了一个新错误。我只想使用 python selenium 和 chrome 驱动程序获取页面源,我不知道为什么没有适合我的解决方案,有什么帮助吗?

我在客户端-服务器中执行此操作,在我的本地即时通讯中使用 windows 并且它的工作良好,但是它的代码不同......

【问题讨论】:

  • executable_path=r'/usr/local/bin/google-chrome' 应该是 chrome 驱动程序而不是 chrome 的路径。您可以从chromedriver.chromium.org/downloads 获取适用于您的 Chrome 版本的 chrome 驱动程序。
  • 我这样做了但仍然无法正常工作,现在我遇到了这个错误:未知错误:Chrome 无法启动:异常退出
  • 您的 Chrome 版本和 Chromedriver 版本是否匹配?这可能会有所帮助github.com/SeleniumHQ/selenium/issues/4961
  • 是的@TekNath ....

标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


【解决方案1】:

此错误消息...

selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 1

...暗示 ChromeDriver 无法启动/产生新的 Browsing ContextChrome Browser 会话。

看来你已经很接近了。通过 Key executable_path 而不是google-chrome 二进制文件的绝对路径 您需要传递绝对路径ChromeDriver 作为 Value。如此有效,您需要替换代码行:

driver = webdriver.Chrome(executable_path=r'/usr/local/bin/google-chrome')

与:

driver = webdriver.Chrome(executable_path='/path/to/chromedriver')

【讨论】:

    【解决方案2】:

    安装此软件包并重试:

    apt-get install -y libglib2.0-0=2.50.3-2 \
        libnss3=2:3.26.2-1.1+deb9u1 \
        libgconf-2-4=3.2.6-4+b1 \
        libfontconfig1=2.11.0-6.7+b1
    

    或者你可以安装 chromium-browser:

    sudo apt-get install -y chromium-browser
    

    【讨论】:

    • 我不是这台服务器上的 sudo 用户,这是我客户端的服务器
    • 无法安装任何软件包?
    猜你喜欢
    • 2017-11-30
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    相关资源
    最近更新 更多