You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Colab运行Selenium报错:chromedriver意外退出(状态码1)求解决方案

解决Colab中Selenium报错"Service chromedriver unexpectedly exited. Status code was: 1"

这个问题大概率是Chrome浏览器与chromedriver版本不兼容导致的——Colab的基础环境会定期更新Chrome版本,而你之前安装的chromedriver版本没跟上,就会触发启动失败。下面是两种可靠的解决方法:

方法一:用webdriver-manager自动匹配版本(推荐)

这个工具会自动检测当前环境的Chrome版本,下载对应的chromedriver,完全不用手动处理版本匹配问题。

  1. 替换安装命令,同时安装selenium和webdriver-manager:
!pip install selenium webdriver-manager
  1. 修改初始化driver的代码,替换原来的启动逻辑:
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
import sys
# 新增两个必要导入
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

options = webdriver.ChromeOptions()
options.add_argument('--headless')        
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# 改用Service和ChromeDriverManager初始化driver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

方法二:手动安装兼容版本的chromedriver

如果不想用第三方工具,可以手动对齐版本:

  1. 先查看当前Colab环境的Chrome版本:
!google-chrome --version
  1. 根据输出的版本号(比如126.0.6478.126),下载对应版本的chromedriver,替换原来的安装步骤:
!apt-get update
# 卸载旧的不兼容chromedriver
!apt-get remove -y chromium-chromedriver
# 替换成你查到的版本号,以下示例为126.0.6478.126
!wget https://storage.googleapis.com/chrome-for-testing-public/126.0.6478.126/linux64/chromedriver-linux64.zip
!unzip chromedriver-linux64.zip
!mv chromedriver-linux64/chromedriver /usr/bin/
!chmod +x /usr/bin/chromedriver
  1. 之后再使用你原来的driver初始化代码即可。

额外提示:如果仍无法启动,可以尝试给options添加--disable-gpu参数,部分环境下需要这个参数才能正常运行headless模式。

内容的提问来源于stack exchange,提问作者NaeBo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 15:35:46