CAPTCHA'ları çözmek için Puppeteerya veya Oyun Yazarına ihtiyacınız yok. Axios ve CaptchaAI ile reCAPTCHA, Turnstile ve resim CAPTCHA'larını saf HTTP isteklerini kullanarak çözebilirsiniz; tarayıcı yüküne gerek kalmaz.
Gereksinimler
| Gereksinim | Ayrıntılar |
|---|---|
| Node.js | 16+ |
| eksenler | 1.x |
| CaptchaAI API anahtarı | Buradan bir tane alın |
npm install axios
CaptchaAI İstemcisi
const axios = require("axios");
class CaptchaAI {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseUrl = "https://ocr.captchaai.com";
}
async submit(params) {
params.key = this.apiKey;
const resp = await axios.get(`${this.baseUrl}/in.php`, { params });
const text = resp.data;
if (!String(text).startsWith("OK|")) {
throw new Error(`Submit failed: ${text}`);
}
return String(text).split("|")[1];
}
async poll(taskId, timeoutMs = 300000) {
const deadline = Date.now() + timeoutMs;
const params = { key: this.apiKey, action: "get", id: taskId };
while (Date.now() < deadline) {
await new Promise((r) => setTimeout(r, 5000));
const resp = await axios.get(`${this.baseUrl}/res.php`, { params });
const text = String(resp.data);
if (text === "CAPCHA_NOT_READY") continue;
if (text.startsWith("OK|")) return text.split("|").slice(1).join("|");
throw new Error(`Solve failed: ${text}`);
}
throw new Error(`Timeout after ${timeoutMs}ms for task ${taskId}`);
}
async solve(params, timeoutMs = 300000) {
const taskId = await this.submit(params);
return this.poll(taskId, timeoutMs);
}
async getBalance() {
const resp = await axios.get(`${this.baseUrl}/res.php`, {
params: { key: this.apiKey, action: "getbalance" },
});
return parseFloat(resp.data);
}
}
module.exports = CaptchaAI;
reCAPTCHA v2'yi çözün (Tarayıcı Yok)
const CaptchaAI = require("./captchaai");
async function main() {
const solver = new CaptchaAI(process.env.CAPTCHAAI_API_KEY);
// Solve the CAPTCHA without opening any browser
const token = await solver.solve({
method: "userrecaptcha",
googlekey: "6Le-wvkS...",
pageurl: "https://staging.example.com/qa-login",
});
// Submit form with the token using Axios
const resp = await axios.post("https://staging.example.com/qa-login", {
username: "user",
password: "pass",
"g-recaptcha-response": token,
});
console.log(`Login response: ${resp.status}`);
}
main().catch(console.error);
Turnstileyi Çöz (Tarayıcı Yok)
const token = await solver.solve({
method: "turnstile",
sitekey: "0x4AAAAA...",
pageurl: "https://example.com",
});
// Submit with Turnstile token
const resp = await axios.post("https://example.com/api/verify", {
"cf-turnstile-response": token,
data: "payload",
});
Resim CAPTCHA'larını Çözün
const fs = require("fs");
const imageBuffer = fs.readFileSync("captcha.png");
const imageB64 = imageBuffer.toString("base64");
const text = await solver.solve({
method: "base64",
body: imageB64,
});
console.log(`CAPTCHA text: ${text}`);
// Submit form with solved text
const resp = await axios.post("https://example.com/verify", {
captcha: text,
other_data: "value",
});
Tam Kazıma İş Akışı
CAPTCHA korumalı bir sayfayı herhangi bir tarayıcı olmadan kazıyın:
const CaptchaAI = require("./captchaai");
const axios = require("axios");
const cheerio = require("cheerio");
async function scrapeProtectedPage(url) {
const solver = new CaptchaAI(process.env.CAPTCHAAI_API_KEY);
// Step 1: Fetch the page
const page = await axios.get(url);
const $ = cheerio.load(page.data);
// Step 2: Extract the reCAPTCHA site key
const siteKey = $(".g-recaptcha").attr("data-sitekey");
if (!siteKey) {
console.log("No CAPTCHA found, returning page content");
return page.data;
}
// Step 3: Solve the CAPTCHA
console.log(`Solving CAPTCHA for ${url}...`);
const token = await solver.solve({
method: "userrecaptcha",
googlekey: siteKey,
pageurl: url,
});
// Step 4: Submit form with token
const formAction = $("form").attr("action") || url;
const formData = {};
$("form input").each((_, el) => {
const name = $(el).attr("name");
const value = $(el).attr("value") || "";
if (name) formData[name] = value;
});
formData["g-recaptcha-response"] = token;
const result = await axios.post(formAction, new URLSearchParams(formData), {
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
return result.data;
}
scrapeProtectedPage("https://example.com/data")
.then((data) => console.log("Success:", typeof data))
.catch(console.error);
Eşzamanlı Çözüm
async function solveBatch(urls, siteKey) {
const solver = new CaptchaAI(process.env.CAPTCHAAI_API_KEY);
const promises = urls.map(async (url) => {
try {
const token = await solver.solve({
method: "userrecaptcha",
googlekey: siteKey,
pageurl: url,
});
return { url, token, error: null };
} catch (error) {
return { url, token: null, error: error.message };
}
});
const results = await Promise.all(promises);
const solved = results.filter((r) => r.token);
console.log(`Solved ${solved.length}/${urls.length}`);
return results;
}
Sorun giderme
| Hata | Sebep | Düzeltme |
|---|---|---|
AxiosError: getaddrinfo ENOTFOUND |
DNS sorunu | Ağ bağlantısını kontrol edin |
Submit failed: ERROR_WRONG_USER_KEY |
Kötü API anahtarı | Anahtarı kontrol panelinden doğrulayın |
Submit failed: ERROR_ZERO_BALANCE |
Fon yok | Hesaba bakiye ekleyin |
| Belirteç hedef site tarafından reddedildi | Jetonun süresi doldu | Tokenı 60 saniye içinde gönderin |
SSS
CAPTCHA çözümü için neden tarayıcılardan tanılamalısınız?
Tarayıcılar örnek başına 200-500 MB RAM tüketir. CaptchaAI ile saf HTTP ~5MB kullanır. Bu, sunucu tarafı otomasyonu için 40-100 kat daha verimlidir.
Ne zaman hala bir tarayıcıya ihtiyacım var?
Site içerik için JavaScript görüntülemeyi gerektirdiğinde. Özellikle CAPTCHA'lar için asla bir tarayıcıya ihtiyacınız olmaz; CaptchaAI, çözümü uzaktan yönetir.
Axios yerine fetch kullanabilir miyim?
Evet. Node.js 18+, yerel fetch'yi içerir. CaptchaAI API parametreleri aynıdır.