reCAPTCHA v2 Invisible 没有可见的复选框。当用户提交表单或单击按钮时,它会自动激活,并且仅当 Google 的风险分析检测到可疑行为时才会显示挑战。这使得自动化检测变得更加困难 - 在表单提交失败之前,您可能不会意识到有验证码。
隐形 reCAPTCHA 与标准 v2 有何不同
| 特征 | reCAPTCHA v2标准 | reCAPTCHA v2 隐形 |
|---|---|---|
| 可见小部件 | 是(复选框) | 否(仅限徽章) |
| 用户交互 | 单击复选框 | 自动提交表单 |
data-size |
normal 或 compact |
invisible |
| 挑战弹出窗口 | 总是有可能 | 仅针对可疑用户 |
| DOM元素 | .g-recaptcha 分区 |
.g-recaptcha div 或程序化 |
检测不可见的 reCAPTCHA
方法一:检查data-size属性
// Browser console
const widgets = document.querySelectorAll('.g-recaptcha');
widgets.forEach((el, i) => {
const size = el.getAttribute('data-size');
const sitekey = el.getAttribute('data-sitekey');
console.log(`Widget ${i}: size=${size}, sitekey=${sitekey}`);
if (size === 'invisible') {
console.log(' → This is Invisible reCAPTCHA');
}
});
方法二:检查徽章
隐形 reCAPTCHA 在角落显示一个小徽章:
const badge = document.querySelector('.grecaptcha-badge');
if (badge) {
console.log('reCAPTCHA badge found — likely Invisible reCAPTCHA');
console.log('Badge visibility:', getComputedStyle(badge).visibility);
}
方法 3:检查 grecaptcha.execute 调用
如果页面使用编程调用(无 .g-recaptcha div):
// Look for grecaptcha.execute in page scripts
document.querySelectorAll('script:not([src])').forEach(s => {
if (s.textContent.includes('grecaptcha.execute')) {
console.log('Found grecaptcha.execute — Invisible reCAPTCHA');
const match = s.textContent.match(/grecaptcha\.execute\s*\(\s*['"]?([^'",\s)]+)/);
if (match) console.log('Sitekey:', match[1]);
}
});
方法四:检查脚本标签渲染参数
document.querySelectorAll('script[src*="recaptcha"]').forEach(s => {
if (s.src.includes('render=') && !s.src.includes('render=explicit')) {
console.log('Invisible/v3 reCAPTCHA detected in script:', s.src);
}
});
使用 CaptchaAI 解决
主要区别:将 invisible=1 传递给 CaptchaAI,以便解算器知道它正在处理 Invisible 变体。
Python
import requests
import time
API_KEY = "YOUR_API_KEY"
# Submit with invisible flag
resp = requests.post("https://ocr.captchaai.com/in.php", data={
"key": API_KEY,
"method": "userrecaptcha",
"googlekey": "6Le-SITEKEY",
"pageurl": "https://staging.example.com/qa-login",
"invisible": "1", # critical for Invisible reCAPTCHA
"json": "1",
}).json()
if resp["status"] != 1:
raise Exception(f"Submit error: {resp['request']}")
task_id = resp["request"]
print(f"Submitted: {task_id}")
# Poll for result
for _ in range(24):
time.sleep(5)
result = requests.get("https://ocr.captchaai.com/res.php", params={
"key": API_KEY, "action": "get", "id": task_id, "json": "1"
}).json()
if result["status"] == 1:
print(f"Token: {result['request'][:50]}...")
break
if result["request"] != "CAPCHA_NOT_READY":
raise Exception(f"Error: {result['request']}")
JavaScript
const axios = require('axios');
const resp = await axios.post('https://ocr.captchaai.com/in.php', null, {
params: {
key: 'YOUR_API_KEY',
method: 'userrecaptcha',
googlekey: '6Le-SITEKEY',
pageurl: 'https://staging.example.com/qa-login',
invisible: 1,
json: 1,
}
});
const taskId = resp.data.request;
console.log(`Submitted: ${taskId}`);
隐形 reCAPTCHA 的token 提交
不可见的 reCAPTCHA 通常绑定到按钮或表单提交。注入后需要触发回调或者提交表单:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://staging.example.com/qa-login")
# After solving, inject and trigger
driver.execute_script("""
// Set the token
document.querySelector('textarea[name="g-recaptcha-response"]').value = arguments[0];
// Find and trigger the callback
var widget = document.querySelector('.g-recaptcha');
var callbackName = widget ? widget.getAttribute('data-callback') : null;
if (callbackName && typeof window[callbackName] === 'function') {
window[callbackName](arguments[0]);
}
""", token)
# Submit the form
driver.find_element(By.CSS_SELECTOR, "form#login").submit()
识别触发元素
不可见的 reCAPTCHA 可以绑定到特定按钮:
<button class="g-recaptcha"
data-sitekey="6Le-SITEKEY"
data-callback="onSubmit"
data-size="invisible">
Submit
</button>
或以编程方式激活:
// Site's code
document.getElementById('submit-btn').addEventListener('click', function() {
grecaptcha.execute();
});
检查两种模式:
// Find elements with g-recaptcha class that are buttons
document.querySelectorAll('button.g-recaptcha, input.g-recaptcha').forEach(el => {
console.log('Trigger element:', el.tagName, el.textContent.trim());
console.log(' data-sitekey:', el.getAttribute('data-sitekey'));
console.log(' data-callback:', el.getAttribute('data-callback'));
});
故障排除
| 问题 | 原因 | 处理方式 |
|---|---|---|
| 令牌被拒绝 | 提交时缺少 invisible=1 |
将 invisible: "1" 添加到 CaptchaAI 请求 |
| 找不到站点密钥 | 没有 .g-recaptcha div |
检查程序化 grecaptcha.render() 或 grecaptcha.execute() 调用 |
| 表单提交但失败 | 回调未触发 | 查找并调用data-callback函数 |
| 未检测到验证码 | 仅针对可疑流量显示 | 检查 grecaptcha-badge 元素或 recaptcha 脚本标签 |
常问问题
如何区分 Invisible v2 和 v3?
Invisible v2 使用 grecaptcha.execute() 而不带 action 参数。 v3 将 grecaptcha.execute(sitekey, {action: 'submit'}) 与操作结合使用。此外,v3 在脚本 URL 中使用 render=SITEKEY。
忘记隐形旗帜有什么关系吗?
是的。如果没有 invisible=1,求解器可能会尝试不同的求解方法,从而生成被站点拒绝的令牌。
我可以在没有浏览器的情况下解决 Invisible reCAPTCHA 问题吗?
是的 - 您只需要站点密钥和页面 URL。浏览器只需要注入token并触发回调即可。
与 CaptchaAI 无缝解决 reCAPTCHA v2 Invisible
获取您的 API 密钥:验证码网站。