青龙面板运行selenium启动Chrome报错

发布于:2025-02-21 ⋅ 阅读:(179) ⋅ 点赞:(0)

Bug Description

在青龙面板运行selenium启动 Chrome 时,出现以下错误:

selenium.common.exceptions.WebDriverException: Message: chrome not reachable

这个错误信息表示 Chrome 浏览器无法被 Selenium 控制。

以下是python中对chrome的配置:

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument('--single-process')
# 使用Selenium启动Chrome浏览器
driver = webdriver.Chrome(options=options)
print('Chrome启动成功')

Solution

后发现删除options.add_argument('--single-process')后,同时指定chromedriver对应路径,service = Service(executable_path='/usr/lib/chromium/chromedriver')后问题解决。我的青龙面板存在两个chromedriver,所以存在这个问题。

service = Service(executable_path='/usr/lib/chromium/chromedriver')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
# 使用Selenium启动Chrome浏览器
driver = webdriver.Chrome(options=options, service=service) 
print('Chrome启动成功')

网站公告

今日签到

点亮在社区的每一天
去签到