【发布时间】:2020-05-21 17:31:27
【问题描述】:
为了表明我已经尽职尽责,对于以下问题,我已经尝试过建议的答案,或者至少阅读并尝试理解:
Selenium python library via docker, Chrome error failed to start: exited abnormally
Chrome crashes when using Selenium(没有回复但我还是看了看)
How to fix "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed" error in Linux? - 对于这个,我用“/etc/alternatives/google-chrome”替换了“/usr/bin/google-chrome”,仍然没有用。
python linux selenium: chrome not reachable
unknown error: Chrome failed to start: crashed(selenium ,headless mode)
python selenium: WebDriverException: Message: chrome not reachable
Selenium chrome failed to start
Selenium webdriver error Chrome failed to start
Python : Selenium - Message: unknown error: Chrome failed to start: exited abnormally
我在 Stack Overflow 上看到了一个常见错误,在我的 Amazon Linux 服务器上使用 Python 运行 Selenium 时,我得到以下结果:
Traceback (most recent call last):
File "test-selenium-chrome.py", line 15, in <module>
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') # Optional argument, if not specified will search path.i
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
这是我的代码:
#!/usr/bin/python3
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display
options = Options()
options.binary_location = '/usr/bin/google-chrome'
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=9515')
options.add_argument('--disable-setuid-sandbox')
display = Display(visible=0, size=(800, 800))
display.start()
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') # Optional argument, if not specified will seearch path.i
driver.maximize_window()
driver.get('http://www.google.com/')
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
我使用的是 Google Chrome 版本 79.0.3945.130,以及 https://sites.google.com/a/chromium.org/chromedriver/downloads 中指定的相应 chromedriver 版本 ChromeDriver 79.0.3945.36
附加信息,如果我只是从命令行运行 google-chrome,我会得到:
[ec2-user@ip-xxx-xx-xx-xxx bin]$ pwd
/usr/bin
[ec2-user@ip-xxx-xx-x-xxx bin]$ google-chrome
Segmentation fault
非常感谢任何帮助。
【问题讨论】:
-
您是否尝试过使用最新的 chrome 驱动程序版本?
-
嗨 Muzzamil,是的,我使用 chromedriver 版本 80.0.3987.16 进行了尝试。仍然得到相同的结果。
-
好的,chrome 驱动程序二进制路径和 chrome 选项的顺序在 webdriver.Chrome() 中是否正确?我认为路径应该是第一位的,然后是选项。
-
嗨 Muzzami,我只是颠倒了顺序并尝试了 driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', options=options) 仍然没有工作。跨度>
-
有人在 github 操作(部署部分)中收到此错误
标签: python linux selenium google-chrome selenium-chromedriver