我正在尝试在 Linux 服务器上运行网络爬虫。完整错误如下
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.10.267518,platform=Linux 4.4.0-141-generic x86_64)
我在 stackoverflow 上看到过类似的问题,解决方案包括“--headless”和“--no-sandbox”参数。但是,我已经在这样做了。
我可以在本地运行这段代码,但是,我无法让它在服务器上运行。
我也检查过一切都是最新的,一切都是。
ChromeDriver 2.10.267518
selenium 3.141.0
这是发生错误的代码片段。
options.add_argument('--headless')
options.add_argument('--no-sandbox')
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(options=options, desired_capabilities=caps, executable_path='/usr/local/bin/chromedriver')
我也尝试过在没有 executable_path 选项的情况下运行上面的代码,但我仍然遇到同样的错误。
最佳答案
我使用的配置文件将 header 值设置为 True,因此代码试图在浏览器中运行但失败了。这是一个愚蠢的错误,但无论如何我都会发布解决方案以防它对某人有所帮助。
我还必须删除下面的行
options.add_argument('--no-sandbox')
并改变这一行
options.add_argument('--headless')
到
options.add_argument('headless')
关于python - selenium.common.exceptions.WebDriverException : Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54561314/