dasdasd
This commit is contained in:
parent
e4e9465bed
commit
572b74afbd
@ -1257,6 +1257,121 @@ class WindsurfRegister {
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试自动点击 checkbox(如果存在)
|
||||
logger.info(this.siteName, ' → 尝试自动点击 checkbox...');
|
||||
try {
|
||||
// 方法1: 通过 iframe.contentFrame() 直接在 iframe 内点击(最正确的方式)
|
||||
const frames = this.page.frames();
|
||||
let clicked = false;
|
||||
|
||||
logger.info(this.siteName, ` → 检测到 ${frames.length} 个 frame`);
|
||||
|
||||
for (const frame of frames) {
|
||||
try {
|
||||
const frameUrl = frame.url();
|
||||
|
||||
// 查找 hCaptcha checkbox 的 iframe(通常包含 checkbox 或 anchor)
|
||||
if (frameUrl.includes('hcaptcha') && (frameUrl.includes('checkbox') || frameUrl.includes('anchor'))) {
|
||||
logger.info(this.siteName, ` → 找到 hCaptcha checkbox frame: ${frameUrl.substring(0, 80)}...`);
|
||||
|
||||
// 在 iframe 内查找 checkbox 并点击
|
||||
const checkboxClicked = await frame.evaluate(() => {
|
||||
// 查找多种可能的 checkbox 元素
|
||||
const checkbox = document.querySelector('#checkbox') ||
|
||||
document.querySelector('.check') ||
|
||||
document.querySelector('[type="checkbox"]') ||
|
||||
document.querySelector('[role="checkbox"]');
|
||||
|
||||
if (checkbox) {
|
||||
checkbox.click();
|
||||
return { success: true, type: 'direct-click' };
|
||||
}
|
||||
|
||||
// 如果找不到 checkbox,尝试点击任何可点击的元素
|
||||
const clickableElements = document.querySelectorAll('div, span, label');
|
||||
for (const el of clickableElements) {
|
||||
const rect = el.getBoundingClientRect();
|
||||
if (rect.width > 0 && rect.height > 0) {
|
||||
el.click();
|
||||
return { success: true, type: 'fallback-click' };
|
||||
}
|
||||
}
|
||||
|
||||
return { success: false };
|
||||
});
|
||||
|
||||
if (checkboxClicked.success) {
|
||||
logger.success(this.siteName, ` → ✓ 已在 iframe 内点击 checkbox (${checkboxClicked.type})`);
|
||||
clicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// 跨域 iframe 或其他错误,继续尝试下一个
|
||||
logger.debug(this.siteName, ` → Frame 访问失败: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 方法2: 如果方法1失败,使用坐标点击
|
||||
if (!clicked) {
|
||||
logger.info(this.siteName, ' → 尝试通过坐标点击...');
|
||||
|
||||
const clickResult = await this.page.evaluate(() => {
|
||||
const iframes = document.querySelectorAll('iframe');
|
||||
|
||||
for (const iframe of iframes) {
|
||||
try {
|
||||
if (iframe.src && iframe.src.includes('hcaptcha')) {
|
||||
const rect = iframe.getBoundingClientRect();
|
||||
// 小的 iframe 是 checkbox(宽高 50-150px)
|
||||
if (rect.width > 50 && rect.width < 150 && rect.height > 50 && rect.height < 150) {
|
||||
return {
|
||||
found: true,
|
||||
x: Math.round(rect.left + rect.width / 2),
|
||||
y: Math.round(rect.top + rect.height / 2),
|
||||
width: Math.round(rect.width),
|
||||
height: Math.round(rect.height)
|
||||
};
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略
|
||||
}
|
||||
}
|
||||
return { found: false };
|
||||
});
|
||||
|
||||
if (clickResult.found) {
|
||||
logger.info(this.siteName, ` → 找到 checkbox iframe: 位置(${clickResult.x}, ${clickResult.y}), 尺寸${clickResult.width}x${clickResult.height}`);
|
||||
await this.page.mouse.click(clickResult.x, clickResult.y);
|
||||
logger.success(this.siteName, ` → ✓ 已点击 checkbox 坐标`);
|
||||
clicked = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (clicked) {
|
||||
// 等待点击生效
|
||||
await this.human.randomDelay(2000, 3000);
|
||||
|
||||
// 验证点击是否生效
|
||||
const tokenFilled = await this.page.evaluate(() => {
|
||||
const response = document.querySelector('[name="h-captcha-response"]') ||
|
||||
document.querySelector('[name="g-recaptcha-response"]');
|
||||
return response && response.value && response.value.length > 20;
|
||||
});
|
||||
|
||||
if (tokenFilled) {
|
||||
logger.success(this.siteName, ' → ✓ Token 已自动填充,验证成功!');
|
||||
} else {
|
||||
logger.info(this.siteName, ' → Token 尚未填充,继续等待验证...');
|
||||
}
|
||||
} else {
|
||||
logger.info(this.siteName, ' → 未找到可点击的 checkbox');
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn(this.siteName, ` → 点击 checkbox 失败: ${e.message}`);
|
||||
}
|
||||
|
||||
await this.human.randomDelay(1000, 2000);
|
||||
|
||||
// 等待验证完成(如果回调成功,应该很快;如果降级到图片,需要手动)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user