selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited with ChromeDriver Selenium Python on Linux

早过忘川 提交于 2021-02-16 21:15:53

问题


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()

I receive this error:

 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

I tried other solutions from the internet but every solution I tried I received a new error. I just want to get page source using python selenium and chrome driver, I don't know why none solutions working for me, any help?

Im do this in client-server, in my local im using windows and its work good, however its different code...


回答1:


This error message...

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

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

Seems you were pretty close. Through the Key executable_path instead of the absolute path of google-chrome binary you need to pass the absolute path of the ChromeDriver as the Value. So effectively, you need to replace the line of code:

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

With:

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



回答2:


Install this packages and try again :

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

or you can install chromium-browser:

sudo apt-get install -y chromium-browser


来源:https://stackoverflow.com/questions/59173996/selenium-common-exceptions-webdriverexception-message-service-usr-bin-google

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!