Code-Auszug
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();
captcha solver Python sdk: nextcaptcha-python
captcha solver Go sdk: nextcaptcha-go
captcha solver C# sdk: nextcaptcha-csharp
Email: [email protected]
Telegram: https://t.me/+wWJh5iON_I0xY2Vh
Website: https://nextcaptcha.com/