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

Undetected Chromedriver报错:'ChromeOptions'对象无'headless'属性

解决Undetected Chromedriver的AttributeError问题

这个错误的核心原因是:undetected-chromedriver(以下简称uc)的ChromeOptions对象不再支持直接设置headless属性,你大概率在代码里写了类似option.headless = True的语句,这和uc的API不兼容。

解决方案

直接通过命令行参数添加无头模式,不要用属性赋值的方式:

方式1:结合标准Selenium Options

from selenium.webdriver.chrome.options import Options
import undetected_chromedriver as uc

option = Options()
# 启用新版无头模式(适配Chrome 112+)
option.add_argument('--headless=new')
# 可选:禁用GPU,避免部分环境报错
option.add_argument('--disable-gpu')

driverr = uc.Chrome(options=option)

方式2:使用uc自带的ChromeOptions

import undetected_chromedriver as uc

option = uc.ChromeOptions()
option.add_argument('--headless=new')

driverr = uc.Chrome(options=option)

补充说明

uc的API更新后,移除了headless属性的直接设置入口,必须通过add_argument传递浏览器启动参数。你之前尝试的option.add_argument('--headless')属于旧版参数,新版Chrome推荐用--headless=new来获得更接近正常浏览器的行为。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 03:33:14