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

如何用Selenium绕过VFS Global网站的Cloudflare复选框验证

解决Cloudflare复选框验证失败问题(针对VFS Global登录页)

Cloudflare的复选框验证核心是浏览器指纹识别和行为分析,自动化环境(包括Selenium/SeleniumBase启动的浏览器)会带有明显的自动化特征,即使手动在这类浏览器中操作也会被判定为非人类行为,导致验证失败。以下是针对性的解决方法:

1. 用Undetected Chromedriver隐藏自动化特征

普通Selenium会暴露navigator.webdriver等标识,Undetected Chromedriver会自动修改Chrome的核心参数,隐藏这些特征,让浏览器指纹更接近真实用户。

示例代码:

import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 初始化浏览器,自动处理指纹伪装
driver = uc.Chrome()
driver.get("https://visa.vfsglobal.com/ind/en/pol/login")

# 等待复选框加载完成后勾选
wait = WebDriverWait(driver, 15)
checkbox = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='checkbox'][name='g-recaptcha-response'] ~ label")))
checkbox.click()

2. 模拟人类操作节奏

机械性的快速操作会被Cloudflare的行为分析识别,需要加入随机延迟和自然的交互动作:

from selenium.webdriver.common.action_chains import ActionChains
import random
import time

# 页面加载后随机延迟1-3秒
time.sleep(random.uniform(1, 3))

# 模拟鼠标移动到复选框,停顿后点击
actions = ActionChains(driver)
actions.move_to_element(checkbox).pause(random.uniform(0.3, 1.2)).click().perform()

3. 复用真实浏览器的用户数据

自动化浏览器默认是全新环境,没有浏览历史、Cookie等数据,这也是被检测的特征之一。可以指定真实Chrome的用户数据目录,让自动化浏览器复用你的日常浏览环境:

options = uc.ChromeOptions()
# Windows路径示例:替换为你的实际用户数据路径
options.add_argument(r"user-data-dir=C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data")
# macOS路径示例:~/Library/Application Support/Google/Chrome/Default
# options.add_argument(r"user-data-dir=/Users/YourUsername/Library/Application Support/Google/Chrome/Default")

driver = uc.Chrome(options=options)
driver.get("https://visa.vfsglobal.com/ind/en/pol/login")

注意:启动前要关闭本地的Chrome浏览器,避免数据冲突。

4. 补充自然行为模拟

除了复选框操作,还可以加入页面滚动、随机鼠标移动等行为,进一步降低被检测概率:

# 模拟随机滚动页面
driver.execute_script(f"window.scrollTo(0, {random.randint(100, 300)})")
time.sleep(random.uniform(0.5, 1.5))

# 随机移动鼠标到页面不同位置
for _ in range(3):
    x = random.randint(100, 800)
    y = random.randint(100, 600)
    actions.move_by_offset(x, y).pause(random.uniform(0.2, 0.8)).perform()

注意事项

  • 不要频繁刷新页面或重复提交验证,否则会触发更严格的验证码(如图片验证码、滑块验证)。
  • 如果使用代理,确保代理IP是干净的(未被Cloudflare标记为恶意IP)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 19:37:14