Join And Get Free Trial!

Thêm giải pháp xác thực vào quá trình tự động hóa của bạn bằng một vài dòng mã#

logoNextCaptcha
March 29,2024

Tự động giải mã captcha bằng NextCAPTCHA#

Nếu bạn tham gia vào các tác vụ tự động hóa trình duyệt như quét web, bạn có thể gặp phải các trang web làm gián đoạn tập lệnh của bạn bằng thử thách hình ảnh xác thực.

Hãy để NEXTCAPTCHA xử lý việc giải mã xác thực của bạn#

Nếu tập lệnh Puppeteer hoặc Playwright của bạn bị chặn bởi các trình phát hiện bot cứng đầu, bạn sẽ muốn kiểm tra điều này. Với một đoạn mã ngắn, nó mang lại cho hệ thống tự động hóa của bạn khả năng giải quyết bất kỳ hình ảnh xác thực nào.

Đoạn mã

const puppeteer= require('puppeteer');
const axios = require('axios');
const url = 'https://www.google.com/recaptcha/api2/demo';
 
async function main() {
    const browser = await puppeteer.launch({
        headless: false
    });
 
    const page = await browser.newPage();
 
    await page.goto(url, {
        waitUntil: 'networkidle0',
    });
 
    const sitekey = await page.$eval('[data-sitekey]', el => el.getAttribute('data-sitekey'));
 
    if (sitekey) {
        const task = await createCaptchaTask(url, sitekey);
        if (task) {
            const result = await getTaskResult(task.taskId);
            if (!result.errorId) {
                await page.evaluate((value) => {
 
                    const textarea = document.querySelector('#g-recaptcha-response');
                    textarea.value = value;
                }, result.solution.gRecaptchaResponse);
                await page.click('#recaptcha-demo-submit');
 
				        // Continue...
            }
        }
 
    } else {
        console.log("find sitekey error");
    }
 
};
 
async function createCaptchaTask(url, siteKey, isInvisible = false) {
    try {
        const data = await axios.post('https://api.nextcaptcha.com/createTask', {
            "clientKey": "CLIENT_KEY", // clientKey from NextCaptcha
            "task": {
                type: "RecaptchaV2TaskProxyless",
                websiteURL: url,
                websiteKey: siteKey,
                isInvisible
            }
        });
        return data.data;
    } catch (e) {
        console.error('createCaptchaTask error', e);
        return null;
    }
}
 
async function sleep(time = 500) {
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve();
        }, time)
    })
}
//
async function getTaskResult(taskId, tryTimes = 60 ) {
    try {
        console.log('tryTimes', tryTimes)
        const data = await axios.post('https://api.nextcaptcha.com/getTaskResult', {
            "clientKey": "CLIENT_KEY", // clientKey from NextCaptcha
            taskId
        });
				if (data.data.status === 'processing' && tryTimes >= 0) {
            await sleep();
            return getTaskResult(taskId, tryTimes-1);
        } else if (data.data.status === 'ready') {
            return data.data;
        } else {
            if (tryTimes < 0) {
                console.error('getTaskResult out of time');
            } else {
                console.error('getTaskResult errorCode', data.data.errorCode);
                console.error('getTaskResult errorDescription', data.data.errorDescription);
                return null;
            }
        }
    } catch (e) {
        console.error('createCaptchaTask error', e.message);
        return null;
    }
}
 
main();
Tập lệnh của bạn sẽ không cần phải thực hiện thêm bất kỳ công việc nào, tất cả những gì cần làm là đợi cho đến khi NextCaptcha được giải quyết bằng API bộ giải của chúng tôi Ngoài ra, chúng tôi còn có sdk trình giải mã xác thực cho Python, Go, C#. và chúng tôi sẽ Tích hợp nhiều ngôn ngữ lập trình hơn

captcha solver Python sdk: nextcaptcha-python

captcha solver Go sdk: nextcaptcha-go

captcha solver C# sdk: nextcaptcha-csharp


Liên hệ với chúng tôi

Email: [email protected]

Telegram: https://t.me/+wWJh5iON_I0xY2Vh

Website: https://nextcaptcha.com/