reCAPTCHA 在两个嵌套 iframe 内呈现:anchor iframe(包含复选框小部件)和 bframe iframe(包含图像挑战)。这些 iframe 包含一些高级自动化工作流程需要提取的编码参数。本指南解释了 iframe 架构、参数格式和提取技术。
reCAPTCHA iframe 架构
Target page (staging.example.com/qa-login)
└── <iframe src="https://www.google.com/recaptcha/api2/anchor?...">
│ ← Anchor iframe: "I'm not a robot" checkbox
│
└── <iframe src="https://www.google.com/recaptcha/api2/bframe?...">
← Bframe iframe: Image challenge grid (loads when clicked)
锚定 iframe
锚点 iframe 包含复选框小部件和初始风险分析:
https://www.google.com/recaptcha/api2/anchor?
ar=1
&k=6LcR_RsTAAAAAN_r0GEkGBfq3L7KmU5JbPHJtwNp ← site key
&co=aHR0cHM6Ly9leGFtcGxlLmNvbTo0NDM. ← encoded origin
&hl=en ← language
&v=jF2Zb_rr_5sv8dMHoGIn-XxY ← reCAPTCHA version
&size=normal ← widget size
&cb=89fu2pf0swif ← callback ID
Bframe iframe
bframe iframe 包含图像挑战(仅在复选框单击触发挑战时加载):
https://www.google.com/recaptcha/api2/bframe?
hl=en
&v=jF2Zb_rr_5sv8dMHoGIn-XxY
&k=6LcR_RsTAAAAAN_r0GEkGBfq3L7KmU5JbPHJtwNp
锚点 URL 参数
| 范围 | 姓名 | 描述 |
|---|---|---|
k |
站点密钥 | reCAPTCHA 站点密钥 |
co |
编码起源 | Base64 编码源(协议 + 域 + 端口) |
v |
版本 | reCAPTCHA JavaScript 捆绑版本哈希 |
hl |
语言 | 挑战语言代码 |
size |
尺寸 | normal、compact 或 invisible |
cb |
打回来 | 唯一的回调函数标识符 |
theme |
主题 | light 或 dark |
ar |
纵横比 | 显示宽高比标志 |
解码co参数
co 参数包含 base64 编码的来源:
import base64
co_value = "aHR0cHM6Ly9leGFtcGxlLmNvbTo0NDM."
# Remove trailing period (padding artifact)
decoded = base64.b64decode(co_value.rstrip(".") + "==").decode()
print(decoded) # "https://example.com:443"
这揭示了 reCAPTCHA 配置的原始域。
提取锚点和 bframe URL
Python从页面源中提取
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, parse_qs
import re
import base64
def extract_recaptcha_iframes(url):
"""Extract reCAPTCHA anchor and bframe iframe URLs and parameters."""
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/120.0.0.0 Safari/537.36",
}
response = requests.get(url, headers=headers, timeout=15)
soup = BeautifulSoup(response.text, "html.parser")
result = {
"anchor_url": None,
"bframe_url": None,
"site_key": None,
"origin": None,
"version": None,
"language": None,
}
# Find anchor iframe
anchor_iframe = soup.find("iframe", src=re.compile(r"recaptcha.*anchor"))
if anchor_iframe:
anchor_url = anchor_iframe.get("src", "")
result["anchor_url"] = anchor_url
# Parse parameters
parsed = urlparse(anchor_url)
params = parse_qs(parsed.query)
result["site_key"] = params.get("k", [None])[0]
result["version"] = params.get("v", [None])[0]
result["language"] = params.get("hl", [None])[0]
# Decode origin
co = params.get("co", [None])[0]
if co:
try:
padded = co.rstrip(".") + "=="
result["origin"] = base64.b64decode(padded).decode()
except Exception:
result["origin"] = co
# Find bframe iframe (may not be in source — loaded dynamically)
bframe_iframe = soup.find("iframe", src=re.compile(r"recaptcha.*bframe"))
if bframe_iframe:
result["bframe_url"] = bframe_iframe.get("src", "")
# Construct bframe URL from anchor parameters if not found
if not result["bframe_url"] and result["site_key"] and result["version"]:
result["bframe_url"] = (
f"https://www.google.com/recaptcha/api2/bframe?"
f"hl={result['language'] or 'en'}"
f"&v={result['version']}"
f"&k={result['site_key']}"
)
return result
iframes = extract_recaptcha_iframes("https://staging.example.com/qa-login")
print(f"Site key: {iframes['site_key']}")
print(f"Origin: {iframes['origin']}")
print(f"Anchor URL: {iframes['anchor_url']}")
Node.js 提取
const axios = require("axios");
const cheerio = require("cheerio");
const { URL } = require("url");
async function extractRecaptchaIframes(pageUrl) {
const { data: html } = await axios.get(pageUrl, {
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
"AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36",
},
timeout: 15000,
});
const $ = cheerio.load(html);
const result = {
anchorUrl: null,
bframeUrl: null,
siteKey: null,
origin: null,
version: null,
};
// Find anchor iframe
const anchorIframe = $("iframe[src*='recaptcha'][src*='anchor']");
if (anchorIframe.length) {
const src = anchorIframe.attr("src");
result.anchorUrl = src;
const url = new URL(src);
result.siteKey = url.searchParams.get("k");
result.version = url.searchParams.get("v");
// Decode origin
const co = url.searchParams.get("co");
if (co) {
try {
result.origin = Buffer.from(
co.replace(/\.$/, ""), "base64"
).toString();
} catch {}
}
}
// Construct bframe URL
if (result.siteKey && result.version) {
result.bframeUrl =
`https://www.google.com/recaptcha/api2/bframe?` +
`hl=en&v=${result.version}&k=${result.siteKey}`;
}
return result;
}
extractRecaptchaIframes("https://staging.example.com/qa-login").then(console.log);
硒提取(动态页面)
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
def extract_iframes_selenium(url):
"""Extract reCAPTCHA iframe URLs from a dynamically loaded page."""
driver = webdriver.Chrome()
driver.get(url)
time.sleep(3) # Wait for reCAPTCHA to load
result = {"anchor_url": None, "bframe_url": None}
# Find all iframes
iframes = driver.find_elements(By.TAG_NAME, "iframe")
for iframe in iframes:
src = iframe.get_attribute("src") or ""
if "recaptcha" in src and "anchor" in src:
result["anchor_url"] = src
elif "recaptcha" in src and "bframe" in src:
result["bframe_url"] = src
driver.quit()
return result
当您需要anchor/bframe URL时
大多数自动化工作流程不需要锚点或 bframe URL。标准CaptchaAI API仅需要sitekey和pageurl。但是,anchor/bframe URL 可用于:
1. 验证正确的站点密钥
当页面有多个 reCAPTCHA 实例或动态加载站点密钥时:
# Extract sitekey from anchor URL when it's not in the page HTML
iframes = extract_recaptcha_iframes(url)
sitekey = iframes["site_key"] # Reliably present in the iframe URL
2. 确定reCAPTCHA版本
# The anchor URL reveals the exact reCAPTCHA version
if "/api2/anchor" in anchor_url:
recaptcha_type = "v2"
elif "/enterprise/anchor" in anchor_url:
recaptcha_type = "enterprise"
3. 匹配域严格实现的源
# Decode the origin from the co parameter
origin = decode_co_parameter(iframes["co"])
# Use this origin as the pageurl for the solver
4.调试解决故障
当令牌被拒绝时,将锚点 URL 参数与求解器请求进行比较可以发现不匹配的情况:
def debug_solve_params(anchor_url, solver_pageurl, solver_sitekey):
"""Compare anchor params with solver request to find mismatches."""
parsed = urlparse(anchor_url)
params = parse_qs(parsed.query)
issues = []
# Check sitekey
anchor_key = params.get("k", [None])[0]
if anchor_key != solver_sitekey:
issues.append(f"Sitekey mismatch: anchor={anchor_key}, solver={solver_sitekey}")
# Check origin
co = params.get("co", [None])[0]
if co:
origin = base64.b64decode(co.rstrip(".") + "==").decode()
solver_parsed = urlparse(solver_pageurl)
solver_origin = f"{solver_parsed.scheme}://{solver_parsed.netloc}"
if origin != solver_origin:
issues.append(f"Origin mismatch: anchor={origin}, solver={solver_origin}")
return issues if issues else ["No mismatches found"]
标准求解(推荐)
对于大多数用例,跳过 iframe 提取并直接使用 CaptchaAI 求解:
import requests
import time
API_KEY = "YOUR_API_KEY"
# All you need: sitekey + pageurl
submit = requests.post("https://ocr.captchaai.com/in.php", data={
"key": API_KEY,
"method": "userrecaptcha",
"googlekey": "6LcR_RsTAAAAAN_r0GEkGBfq3L7KmU5JbPHJtwNp",
"pageurl": "https://staging.example.com/qa-login",
"json": 1,
})
task_id = submit.json()["request"]
for _ in range(60):
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.get("status") == 1:
token = result["request"]
print(f"Token: {token[:50]}...")
break
仅当标准解决由于需要更深入调查的站点密钥或域问题而失败时才需要 Anchor/bframe 提取。
常见问题
我是否需要向 CaptchaAI 提供锚点或 bframe URL?
不需要。CaptchaAI 只需要 sitekey 和 pageurl。解算器在内部处理锚点和 bframe 交互。提取这些 URL 对于调试很有用,但对于解决问题不是必需的。
为什么bframe iframe没有出现在页面源中?
当用户单击复选框并触发质询时,bframe iframe 由 reCAPTCHA 的 JavaScript 动态创建。它不存在于初始 HTML 中。您需要 Selenium 或 Puppeteer 来与小部件交互并捕获 bframe URL。
锚点 URL 中的 v 参数是什么?
v 参数是 reCAPTCHA JavaScript 捆绑版本哈希。当 Google 更新 reCAPTCHA 时,它会定期更改。求解时不需要它 — CaptchaAI 自动处理版本差异。
co 参数可以帮助调试域问题吗?
是的。 co 参数是 base64 编码的源(协议 + 域 + 端口)。解码它可以准确地揭示 reCAPTCHA 认为它正在哪个域上运行。如果这与您提交令牌的域不匹配,则您已发现域不匹配导致令牌拒绝。
概括
reCAPTCHA 使用两个 iframe:anchor(复选框小部件)和 bframe(图像挑战)。锚点 URL 包含站点密钥、编码来源和版本哈希。对于标准求解CaptchaAI,您只需要 sitekey 和 pageurl — 无需提取 iframe URL。使用 iframe 提取技术来调试域验证失败或从动态加载的页面中提取站点密钥。
相关文章
- 如何使用Api解决Recaptcha V2回调
- Recaptcha V2 Turnstile同一站点处理
- Recaptcha V2回调机制