使用undetected_chromedriver 3.4.6启动无头Chrome时遇TypeError错误求助
解决undetected_chromedriver 3.4.6无头模式启动时的TypeError错误
针对你遇到的TypeError: '<' not supported between instances of 'NoneType' and 'int'错误,以下是几个可行的解决方向:
替换无头模式参数
新版本的--headless=new在undetected_chromedriver 3.4.6中存在兼容性问题,换成旧版的--headless=chrome参数即可:options.add_argument("--headless=chrome")手动指定Chrome二进制路径
若undetected_chromedriver自动匹配Chrome版本失败,会导致版本号为None引发比较错误。直接指定Chrome的安装路径:# Windows示例 options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" # macOS示例 # options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" # Linux示例 # options.binary_location = "/usr/bin/google-chrome"升级undetected_chromedriver版本
3.4.6属于较旧版本,该问题大概率已在后续版本中修复,执行升级命令:pip install --upgrade undetected-chromedriver检查Chrome版本兼容性
undetected_chromedriver 3.4.6适配的Chrome版本范围大致为114-116。如果你的Chrome版本过高,要么降级Chrome,要么升级undetected_chromedriver到对应兼容版本。
修改后的完整代码示例(使用旧无头参数+可选指定路径):
from undetected_chromedriver import Chrome, ChromeOptions options = ChromeOptions() options.add_argument("--headless=chrome") options.add_argument("--password-store=basic") options.add_experimental_option( "prefs", { "credentials_enable_service": False, "profile.password_manager_enabled": False, }, ) # 可选:添加Chrome路径 # options.binary_location = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe" driver = Chrome(options=options) driver.get('https://www.google.com/')
内容的提问来源于stack exchange,提问作者anilraj
相关产品推荐
相关产品推荐

