unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=...)
linux下命令行运行报错
Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752),platform=Linux 4.14.0-deepin2-amd64 x86_64)
解决方案一
先执行一下两句安装命令(以ubuntu为例):
pip install pyvirtualdisplay
sudo apt-get install xvfb
然后添加如下代码:(必须在Linux下执行)
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 800))
display.start()
driver = webdriver.Chrome()
解决方案二
You are using arg --headless so with that my be you can try with another argument --no-sandbox and window-size=1024,768.
chrome.additional.capabilities={"chromeOptions":{"args":["--headless", "window-size=1024,768", "--no-sandbox"], "binary": "/home/ubuntu/software/chromedriver"}}
You can refer following
https://stackoverflow.com/questions/22558077/unknown-error-chrome-failed-to-start-exited-abnormally-driver-info-chromedri
https://github.com/SeleniumHQ/selenium/issues/4961
按照上面给出的解决方案把代码修改如下:
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument("window-size=1024,768")
#添加沙盒模式
chrome_options.add_argument("--no-sandbox")
driver = webdriver.Chrome(chrome_options=chrome_options)