selenium.common.exceptions.WebDriverException:消息:在Linux上,ChromeDriver Selenium Python意外退出了服务/usr/bin/google-chrome [英] selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited with ChromeDriver Selenium Python on Linux
问题描述
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
我尝试了Internet上的其他解决方案,但是尝试的每个解决方案都收到了一个新错误.我只想使用python硒和chrome驱动程序获取页面源,我不知道为什么没有解决方案对我有用,有帮助吗?
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?
我在本地服务器上使用Windows在客户端服务器中执行此操作,它的工作很好,但是它的代码不同...
Im do this in client-server, in my local im using windows and its work good, however its different code...
推荐答案
此错误消息...
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited. Status code was: 1
...表示 ChromeDriver 无法启动/产生新的浏览上下文,即 Chrome浏览器会话.
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
您似乎很接近.通过 Key executable_path
,而不是 google-chrome
二进制文件的绝对路径需要通过 ChromeDriver 的绝对路径作为 Value .如此有效,您需要替换以下代码行:
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')
使用:
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
这篇关于selenium.common.exceptions.WebDriverException:消息:在Linux上,ChromeDriver Selenium Python意外退出了服务/usr/bin/google-chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!