Hướng Dẫn API

Giải CAPTCHA hình ảnh lưới bằng Node.js và CaptchaAI

CAPTCHA hình ảnh lưới hiển thị lưới 3×3 hoặc 4×4 với hướng dẫn như "chọn tất cả các ô vuông có đèn giao thông". Hướng dẫn này chỉ ra cách giải quyết chúng từ Node.js bằng cách sử dụngCaptchaAIvà Puppeteer.


Điều kiện tiên quyết

Mục Giá trị
Khóa API CaptchaAI Từcaptchaai.com
Node.js 14+
Thư viện axios, puppeteer

Bước 1: Chụp ảnh lưới

const puppeteer = require('puppeteer');
const fs = require('fs');

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com/page-with-recaptcha');

// Switch to the reCAPTCHA challenge iframe
const frames = page.frames();
const challengeFrame = frames.find((f) => f.url().includes('recaptcha/api2/bframe'));

// Get the instruction text
const instruction = await challengeFrame.$eval(
  '.rc-imageselect-desc-no-canonical',
  (el) => el.textContent.trim()
);

// Screenshot the grid
const grid = await challengeFrame.$('.rc-imageselect-target');
await grid.screenshot({ path: 'grid.png' });

Bước 2: Gửi tới CaptchaAI

const axios = require('axios');
const FormData = require('form-data');

const API_KEY = 'YOUR_API_KEY';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));

const form = new FormData();
form.append('key', API_KEY);
form.append('method', 'post');
form.append('grid_size', '3x3');
form.append('img_type', 'recaptcha');
form.append('instructions', instruction);
form.append('json', '1');
form.append('file', fs.createReadStream('grid.png'));

const { data: submitData } = await axios.post('https://ocr.captchaai.com/in.php', form, {
  headers: form.getHeaders(),
});

if (submitData.status !== 1) throw new Error(submitData.request);
const taskId = submitData.request;
console.log(`Task submitted: ${taskId}`);

Bước 3: Thăm dò ý kiến giải pháp

await sleep(5000);

let cellsToClick;
for (let i = 0; i < 30; i++) {
  const { data: pollData } = await axios.get('https://ocr.captchaai.com/res.php', {
    params: { key: API_KEY, action: 'get', id: taskId, json: 1 },
  });

  if (pollData.status === 1) {
    cellsToClick = JSON.parse(pollData.request);
    console.log('Click cells:', cellsToClick);
    break;
  }
  if (pollData.request !== 'CAPCHA_NOT_READY') {
    throw new Error(pollData.request);
  }
  await sleep(5000);
}

Bước 4: Bấm vào các ô đúng

const tiles = await challengeFrame.$$('.rc-imageselect-tile');

for (const cellNum of cellsToClick) {
  await tiles[cellNum - 1].click();
  await sleep(300);
}

// Click verify
await challengeFrame.click('#recaptcha-verify-button');
console.log(`Solved: clicked tiles ${JSON.stringify(cellsToClick)}`);
await browser.close();

Sản lượng dự kiến:

Click cells: [1, 3, 6, 9]
Solved: clicked tiles [1,3,6,9]

Câu hỏi thường gặp

Tính năng này có hoạt động với lưới 4×4 không?

Vâng. Đặt grid_size thành 4x4 trong tham số yêu cầu.

Tôi có thể sử dụng Playwright thay vì Puppeteer không?

Vâng. Các lệnh gọi API CaptchaAI giống nhau — chỉ có mã tự động hóa trình duyệt thay đổi.

Điều gì sẽ xảy ra nếu CAPTCHA làm mới bằng hình ảnh mới?

Một số thử thách reCAPTCHA tải các ô mới. Bạn có thể cần phải chụp và gửi lại cho mỗi vòng.


Hướng dẫn liên quan


Bắt đầu giải Grid Image CAPTCHA bằng CaptchaAI →

Os comentários estão desativados para este artigo.