天天看點

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)

找到一種解決方案(這種方法對我不起作用,往下看)https://blog.csdn.net/xuwukui/article/details/79042994

先執行一下兩句安裝指令(以ubuntu為例):

pip install pyvirtualdisplay
sudo apt-get install xvfb           

複制

然後添加如下代碼:

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 800))  
display.start()
driver = webdriver.Chrome()           

複制

google到另外一種解決方案,完美解決https://groups.google.com/forum/#!topic/qaf-users/ZRUbGWSL7Y8

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)           

複制

參考:https://blog.csdn.net/daocaoren92wq/article/details/80155595