[英]chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed error using Selenium through Python
Before I begin: I know there are a billion posts about Selenium not working, and various solutions to try.在我开始之前:我知道有十亿个关于 Selenium 不起作用的帖子,以及各种尝试的解决方案。 I believe I've tried everything, but forgive me if I am missing something.
我相信我已经尝试了一切,但如果我遗漏了什么,请原谅我。 I'm hitting my head against a wall and would appreciate help.
我的头撞在墙上,希望得到帮助。
Here are some steps I have taken:以下是我采取的一些步骤:
I downloaded the chromedriver for selenium (Ubuntu, Python) and used chmod 755
and also chmod 777
to make the driver executable.我下载了 selenium(Ubuntu,Python)的 chromedriver,并使用
chmod 755
和chmod 777
使驱动程序可执行。 Afterwords, I started the chromedriver with ./chromedriver
.之后,我用 ./chromedriver 启动了
./chromedriver
。
I've tried various options for Selenium, including manually adding the port that the chromedriver is running on我尝试了 Selenium 的各种选项,包括手动添加运行 chromedriver 的端口
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/home/myname/projects/myproject/chromedriver"
options.add_argument("--remote-debugging-port=9515")
chrome_driver_binary = '/home/myname/projects/myproject/chromedriver'
driver = webdriver.Chrome(chrome_driver_binary, options = options)
driver.get('http://www.ubuntu.com/')
I've tried options suggested in other posts, like these:我已经尝试过其他帖子中建议的选项,例如:
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-setuid-sandbox")
I've made sure that I am using a chromedriver that is compatable with my version of Chrome.我确保我使用的是与我的 Chrome 版本兼容的 chromedriver。
Nothing has seemed to work.似乎没有任何效果。 I keep getting this error:
我不断收到此错误:
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(chrome not reachable)
(The process started from chrome location /home/myname/projects/myproject/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
I'd sincerely appreciate someone else's interpretation of this problem.我真诚地感谢别人对这个问题的解释。
You need to take care of a couple of things as follows:您需要注意以下几点:
options.binary_location
: Refers to the google-chrome binary location and is used if Google Chrome isn't installed at the default location. options.binary_location
:指的是google-chrome二进制位置,如果Google Chrome未安装在默认位置,则使用该位置。 See: WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome请参阅: WebDriverException:未知错误:对于旧版本的 Google Chrome,在 Python 中找不到带有 Selenium 的 Chrome 二进制错误
--remote-debugging-port
: If you aren't remote debugging, you can drop this argument safely. --remote-debugging-port
:如果您不是远程调试,则可以安全地删除此参数。
chrome_driver_binary
: Referes to the absolute location of the ChromeDriver within your system. chrome_driver_binary
:指ChromeDriver在系统中的绝对位置。
webdriver.Chrome(chrome_driver_binary, options = options)
: Additionally you may like to add the key executable_path as as follows: webdriver.Chrome(chrome_driver_binary, options = options)
:此外,您可能希望添加key executable_path ,如下所示:
chrome_driver_binary = '/home/myname/projects/myproject/chromedriver' driver = webdriver.Chrome(executable_path=chrome_driver_binary, options = options) driver.get('http://www.ubuntu.com/')
--no-sandbox
, --headless
, --disable-dev-shm-usage
, --disable-setuid-sandbox
, etc are optional settings which you may not require to start off. --no-sandbox
、 --headless
、 --disable-dev-shm-usage
、 --disable-setuid-sandbox
等是您可能不需要启动的可选设置。
The minimum code block to initiate a Selenium driven ChromeDriver initiated google-chrome Browsing Context can be:启动Selenium驱动的ChromeDriver启动的 google-chrome浏览上下文的最小代码块可以是:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
driver = webdriver.Chrome(executable_path='/home/myname/projects/myproject/chromedriver', options=options)
driver.get("http://www.ubuntu.com/")
A common cause for Chrome to crash during startup is running Chrome as
root
user (administrator
) on Linux.Chrome 在启动期间崩溃的一个常见原因是在 Linux 上以
root
用户(administrator
)身份运行 Chrome。 While it is possible to work around this issue by passing--no-sandbox
flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged.虽然可以通过在创建 WebDriver session 时传递
--no-sandbox
标志来解决此问题,但不支持并且强烈建议不要使用此类配置。 You need to configure your environment to run Chrome as a regular user instead.您需要将环境配置为以普通用户身份运行 Chrome。
You can find a couple of relevant detailed discussions in:您可以在以下位置找到一些相关的详细讨论:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.