【发布时间】:2022-01-24 16:11:06
【问题描述】:
在我开始之前:我知道有十亿篇关于 Selenium 不起作用的帖子,并且有各种解决方案可以尝试。我相信我已经尝试了一切,但如果我遗漏了什么,请原谅我。我的头撞墙了,希望能得到帮助。
以下是我采取的一些步骤:
我下载了 selenium(Ubuntu、Python)的 chromedriver,并使用 chmod 755 和 chmod 777 使驱动程序可执行。后记,我用./chromedriver启动了chromedriver。
我为 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/')
我尝试过其他帖子中建议的选项,例如:
options.add_argument('--no-sandbox')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--disable-setuid-sandbox")
我已确定我使用的是与我的 Chrome 版本兼容的 chromedriver。
似乎没有任何效果。我不断收到此错误:
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.)
我真诚地感谢别人对这个问题的解释。
【问题讨论】:
-
我建议使用 headless 选项,并且在一个项目中,我在调用任何网站之前使用了 .implicitly_wait(10) 函数。我也会选择 Chromium 作为驱动程序。
-
感谢您的回复!我放弃并尝试了 Firefox,这是我第一次尝试。这种情况对我来说仍然是一个谜,我感谢任何人对上述代码中可能有什么问题的意见。
标签: python selenium google-chrome selenium-webdriver selenium-chromedriver