Bypassing Recaptcha V2 with NodeJS and Puppeteer
What you're going to learn
- নতুনভাবে ইনস্টল করা Ubuntu OS -এ NodeJS এবং Webstorm IDE আইডিই সেটআপ করুন।
- anticaptchaofficial এবং puppeteer npm মডিউল ইনস্টল এবং ইম্পোর্ট করুন।
- কীভাবে Recaptcha এবং NodeJS স্ক্রিপ্টের সাথে এই ফর্ম জমা দিতে হয় তা আপনি শিখবেন।
- কীভাবে puppeteer স্ক্রিপ্ট লিখবেন যেটি ব্যাকগ্রাউন্ড মোডে Chromium খুলবে এবং একটি পেজে নেভিগেট করবে তা শিখুন।
- কীভাবে কোনও পেজের স্ক্রিনশট নিতে এবং এটি একটি ডিস্কে সংরক্ষণ করতে হয় তা শিখুন।
- CSS নির্বাচক ব্যবহার করে কীভাবে ফর্ম বার্তা ক্ষেত্র পূরণ করতে হয় তা শিখুন।
- কীভাবে Recaptcha v2 সমাধান করবেন, গোপন বার্তা এরিয়া #g-recaptcha-response পূরণ করতে হয় এবং ফর্মটি জমা দিতে হয় তা শিখুন।
- জাভাস্ক্রিপ্ট ES6 এবং NodeJS সম্পর্কে আপনার জ্ঞান বাড়ানোর বিষয়ে নোটসমূহ।
নতুনভাবে ইনস্টল করা Ubuntu OS -এ NodeJS এবং Webstorm IDE আইডিই সেটআপ করুন।
- Ubuntu OS: Installing Ubuntu OS is not a requirement, but a recommendation. Running NodeJS from Windows is also possible, but our code may not be compatible.
- Node JS: Download NodeJS for your operating system here
- Code editor: Recommended VS Code or Atom. Both are free IDE.
Install curl and nodejs in Ubuntu:
apt update apt install -y curl curl -fsSL https://deb.nodesource.com/setup_18.x | bash - apt install -y nodejs
anticaptchaofficial এবং puppeteer npm মডিউল ইনস্টল এবং ইম্পোর্ট করুন।
Install anti-captcha and Puppeteer npm modules:
npm install @antiadmin/anticaptchaofficial puppeteer
Create a new file index.js and add the following. Replace "YOUR_API_KEY" with your key from API settings :
const ac = require("@antiadmin/anticaptchaofficial");
const pup = require("puppeteer");
ac.setAPIKey('YOUR_API_KEY');
কীভাবে puppeteer স্ক্রিপ্ট লিখবেন যেটি ব্যাকগ্রাউন্ড মোডে Chromium খুলবে এবং একটি পেজে নেভিগেট করবে তা শিখুন।
Add the following code to first solve captcha, then fill the form with login and password, paste g-response token to the textarea with id="g-recaptcha-response" and submit the form:
const login = 'mylogin';
const password = 'my strong password';
(async () => {
console.log('solving recaptcha ...');
let token = await ac.solveRecaptchaV2Proxyless('https://anti-captcha.com/demo?page=recaptcha_v2_textarea', '6LfydQgUAAAAAMuh1gRreQdKjAop7eGmi6TrNIzp');
if (!token) {
console.log('something went wrong');
return;
}
console.log('opening browser ..');
const browser = await pup.launch();
console.log('creating new tab ..');
const tab = await browser.newPage();
console.log('changing window size .. ');
await tab.setViewport({ width: 1360, height: 1000 });
console.log('opening target page ..');
await tab.goto('https://anti-captcha.com/demo?page=recaptcha_v2_textarea', { waitUntil: "networkidle0" });
console.log('filling login input ..');
await tab.$eval('#contentbox > form > div > div:nth-child(1) > span > input', (element, login) => {
element.value = login;
}, login);
console.log('filling password input');
await tab.$eval('#contentbox > form > div > div:nth-child(2) > span > input', (element, password) => {
element.value = password;
}, password);
console.log('setting recaptcha g-response ...');
await tab.$eval('#g-recaptcha-response', (element, token) => {
element.value = token;
}, token);
console.log('submitting form .. ');
await Promise.all([
tab.click('#contentbox > form > div > div.tac.padding20px > button'),
tab.waitForNavigation({ waitUntil: "networkidle0" })
]);
console.log('making a screenshot ...');
await tab.screenshot({ path: 'screenshot.png' });
console.log('closing browser .. ');
await browser.close();
})();
You may note that we first solve the captcha and only then navigate to the page and paste the result. It works for Recaptcha as we already know the sitekey and lifetime of the token is 120 seconds.
The screenshot of the final page is saved to screenshot.png. If you wish to see what's going on in the browser, switch off the headless mode:
console.log('opening browser ..');
//const browser = await pup.launch();
const browser = await pup.launch({ headless: false });
জাভাস্ক্রিপ্ট ES6 এবং NodeJS সম্পর্কে আপনার জ্ঞান বাড়ানোর বিষয়ে নোটসমূহ।
You've learned how to bypass a form with Recaptcha V2 in it's simplest implementation way - with "g-recaptcha-response" textarea as part of the form. You may want to extend your knowledge:
- NodeJS এবং Puppeteer ব্যবহার করে একটি কলব্যাক ফাংশন সহ কিভাবে Recaptcha V2 বাইপাস করবেন ফর্ম শিখুন।
- Recommended NodeJS and Javascript ES6 courses by Maximilian Schwarzmüller: NodeJS - The Complete Guide and Accelerated ES6 Javascript Training