Menu

Bypassing Recaptcha V2 with NodeJS and Puppeteer


What you're going to learn

  • تازہ انسٹال کیے گئے Ubuntu OS میں NodeJS اور Webstorm IDE سیٹ اپ کریں۔
  • anticaptchaofficial اور puppeteer npm ماڈیولز انسٹال اور درآمد کریں۔
  • آپ NodeJS script اسکرپٹ کے ذریعے Recaptcha کے ساتھ یہ فارم جمع کروانے کا طریقہ جانیں گے۔
  • puppeteer اسکرپٹ لکھنے کا طریقہ جانیں جو بیک گراؤنڈ موڈ میں Chromium کھولتا ہے اور پیج پر نیویگیٹ کرتا ہے۔
  • پیج کا اسکرین شاٹ لینے اور اسے ڈسک پر محفوظ کرنے کا طریقہ جانیں۔
  • CSS سیلیکٹرز استعمال کرتے ہوئے فارم کی ٹیکسٹ فیلڈز پُر کرنے کا طریقہ جانیں۔
  • Recaptcha v2 حل کرنے کا طریقہ جانیں، پوشیدہ textarea #g-recaptcha-response پُر کریں اور فارم جمع کروائیں۔
  • جاوا اسکرپٹ ES6 اور NodeJS کے بارے میں اپنا علم بڑھانے کے بارے میں نوٹس۔
Source code

تازہ انسٹال کیے گئے 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:

Github

https://github.com/anti-captcha/solving-captcha-concepts/blob/master/tutorial1.js