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

Selenium测试卡在Cloudflare站点安全验证页面问题求助

解决Selenium无痕模式下Cloudflare站点安全验证拦截问题

针对你遇到的Selenium触发Cloudflare验证、手动访问正常的问题,给你几个实用的解决思路:

1. 补全浏览器指纹模拟,强化真实度

仅禁用AutomationControlled还不够,Cloudflare会检测多个浏览器特征,你需要补充以下参数让Selenium更像真实用户:

ChromeOptions options = new();
// 保留原有参数
options.AddArguments("--incognito");
options.AddArguments("--ignore-ssl-errors=yes");
options.AddArguments("--ignore-certificate-errors");
options.AddArguments("--disable-gpu");
options.AddArguments("--lang=en");
options.AddArguments("--disable-infobars");
options.AddArguments("--window-size=1920,1080");
options.AddArguments("--disable-blink-features=AutomationControlled");

// 新增模拟真实浏览器的关键参数
options.AddArguments("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"); // 替换成当前Chrome最新UA
options.AddExcludedArgument("enable-automation");
options.AddAdditionalChromeOption("useAutomationExtension", false);

2. 加入真人化操作延迟与行为

Cloudflare会识别机械性的快速操作,在访问页面后加入随机等待、模拟鼠标移动,让行为更自然:

driver.Navigate().GoToUrl("目标页面地址");
// 随机等待2-5秒,模拟用户加载等待
Random random = new Random();
Thread.Sleep(random.Next(2000, 5000));

// 模拟鼠标移动到页面主体区域
Actions actions = new Actions(driver);
actions.MoveToElement(driver.FindElement(By.TagName("body"))).Perform();

3. 改用undetected-chromedriver库

如果手动调参数无效,可以用专门绕过反爬检测的undetected-chromedriver,它会自动处理Cloudflare的多数检测点:

  • 先通过NuGet安装:Install-Package UndetectedChromeDriver
  • 使用示例:
var options = new ChromeOptions();
options.AddArguments("--incognito");
// 按需添加其他自定义参数
var driver = UndetectedChromeDriver.Create(options);
driver.Navigate().GoToUrl("目标页面地址");

4. 排查IP/代理异常

如果你的测试用IP是服务器IP,大概率被Cloudflare标记为异常IP池,尝试切换到住宅IP或使用代理池轮换IP,避免单一IP高频访问。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 22:44:51