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

Ubuntu ARM64架构下Selenium调用Chromedriver失败求助

问题解决:ARM64 Ubuntu下Selenium无法获取Chrome驱动

错误原因

你代码里犯了一个关键错误:chromeOptions.binary_location被设置为chromedriver的路径,这个参数的作用是指定浏览器(Chromium)的二进制文件位置,而非驱动程序的位置。同时Selenium 4.x自带的Selenium Manager会自动管理驱动,错误的参数设置干扰了它的正常工作,导致抛出"无法使用Selenium Manager获取Chrome驱动"的异常。

解决方案步骤

1. 确认Chromium浏览器的实际路径

由于你是通过snap安装的Chromium,执行以下命令获取浏览器路径:

which chromium

通常输出为/snap/bin/chromium,也可以使用完整路径/snap/chromium/current/usr/lib/chromium-browser/chromium。

2. 修正代码中的参数设置

根据你使用的Selenium版本,选择以下两种修正方式:

方式一:Selenium 4.x推荐的Service类写法

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

def myFunc(URL):
    webDriver = None

    try:
        # 指定chromedriver路径
        chrome_driver_path = '/usr/bin/chromedriver'
        # 指定Chromium浏览器路径
        chromium_binary_path = '/snap/bin/chromium'
        
        chromeOptions = Options()
        chromeOptions.add_argument("--headless=new")
        chromeOptions.add_argument("--start-maximized")
        chromeOptions.binary_location = chromium_binary_path
        
        # 使用Service类传入驱动路径
        service = Service(chrome_driver_path)
        webDriver = webdriver.Chrome(service=service, options=chromeOptions)
        
        webDriver.get(URL)

        # 执行你的操作
        # Do something....

    except Exception as e:
        print(e)
        if webDriver is not None:
            webDriver.quit()
            webDriver = None

    return webDriver

方式二:旧版Selenium(<4.0)的executable_path写法

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def myFunc(URL):
    webDriver = None

    try:
        chrome_driver_path = '/usr/bin/chromedriver'
        chromium_binary_path = '/snap/bin/chromium'
        
        chromeOptions = Options()
        chromeOptions.add_argument("--headless=new")
        chromeOptions.add_argument("--start-maximized")
        chromeOptions.binary_location = chromium_binary_path
        
        # 直接传入executable_path参数
        webDriver = webdriver.Chrome(executable_path=chrome_driver_path, options=chromeOptions)
        
        webDriver.get(URL)

        # 执行你的操作
        # Do something....

    except Exception as e:
        print(e)
        if webDriver is not None:
            webDriver.quit()
            webDriver = None

    return webDriver

3. 额外验证

  • 确保/usr/bin/chromedriver有可执行权限,可执行chmod +x /usr/bin/chromedriver确认
  • 再次验证Chromium和ChromeDriver的版本完全匹配(你当前的版本是一致的,这部分没问题)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 02:42:44