【问题标题】:Python Selenium ChromeDriver Throws Chrome failed to start ErrorPython Selenium ChromeDriver 引发 Chrome 无法启动错误
【发布时间】:2021-04-14 15:42:56
【问题描述】:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = driver_path
options.add_argument("--start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")

driver = webdriver.Chrome(options=options, executable_path=driver_path)

上面的代码不会成功运行chromedriver,它的错误信息是:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: was killed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location ${driver_path} is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

我看到一些建议将包含驱动程序文件的文件夹设置为路径,但我不想使用该方法,所以我没有尝试过。

我不知道为什么司机被杀。驱动程序是最新的,并且版本与安装的 Chrome 浏览器匹配。计算机有 24GB 的额外 RAM,因此不太可能是 RAM 问题。奇怪的是,该代码在我的笔记本电脑上运行,但在我的台式机上却不行。

【问题讨论】:

    标签: python selenium


    【解决方案1】:

    请您在删除引号后确认 考虑到你已经声明了driver_path

    driver = webdriver.Chrome(options=options, executable_path=driver_path)
    

    【讨论】:

    • 那只是错字。我正确地声明了driver_path。很抱歉这个错误
    【解决方案2】:

    听起来像是目录问题。尝试使 driver_path 成为复制 Web 驱动程序 exe 路径的字符串。例如:r"C:\Users\Person\chromeWebDriver.exe"

    用户 r"" 以确保它忽略反斜杠。试试看你能不能用直接路径启动它,看看它是否是一个目录问题。

    【讨论】:

    • 我确实使用了原始字符串。错误消息并没有说它找不到驱动程序;它说司机被杀了。
    • 尝试“chrome_options - Options()”然后“chrome_options.use_experimental_options("detach" = True)”
    【解决方案3】:

    我刚刚得到了解决方案。许多解决方案建议options.binary_location 的值应该是ChromeDriver Path,但它必须是Chrome Browser Binary Path。所以这才成功:

    options = Options()
    options.binary_location = chrome_path
    options.add_argument("--start-maximized")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")
    
    driver = webdriver.Chrome(options=options, executable_path=driver_path)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多