问题描述:用python写了个爬虫,pycharm中运行正常,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)
google解决方案:/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/questions/22558077/unknown-error-chrome-failed-to-start-exited-abnormally-driver-info-chromedri/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)