Blog
How to solve reCaptcha v2 with Node.JS

How to solve reCaptcha v2 with Node.JS

Logo of Capsolver

CapSolver Blogger

How to use capsolver

27-Sep-2023

Bypassing reCaptcha v2, reCaptcha v2 with Node.JS, reCaptcha v2 Node.JS solver

⚙️ Prerequisites

  • Proxy (Optional)
  • Node.JS installed
  • Capsolver API key

🤖 Step 1: Install Necessary Packages

Execute the following commands to install the required packages:

npm install axios

👨‍💻 Node.JS Code for solve reCaptcha v2 without proxy

Here's a Node.JS sample script to accomplish the task:

const axios = require('axios');

const PAGE_URL = ""; // Replace with your Website
const SITE_KEY = ""; // Replace with your Website
const CLIENT_KEY = "";  // Replace with your CAPSOLVER API Key

async function createTask(payload) {
  try {
    const res = await axios.post('https://api.capsolver.com/createTask', {
      clientKey: CLIENT_KEY,
      task: payload
    });
    return res.data;
  } catch (error) {
    console.error(error);
  }
}
async function getTaskResult(taskId) {
    try {
        success = false;
        while(success == false){

            await sleep(1000);
        console.log("Getting task result for task ID: " + taskId);
      const res = await axios.post('https://api.capsolver.com/getTaskResult', {
        clientKey: CLIENT_KEY,
        taskId: taskId
      });
      if( res.data.status == "ready") {
        success = true;
        console.log(res.data)
        return res.data;
      }
    }
  
    } catch (error) {
      console.error(error);
      return null;
    }
  }
  

async function solveReCaptcha(pageURL, sitekey) {
  const taskPayload = {
    type: "ReCaptchaV2TaskProxyless",
    websiteURL: pageURL,
    websiteKey: sitekey,
  };
  const taskData = await createTask(taskPayload);
  return await getTaskResult(taskData.taskId);
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
  try {
   
      const response = await solveReCaptcha(PAGE_URL, SITE_KEY );
      console.log(`Received token: ${response.solution.gReCaptcharesponse}`);
        
    }
catch (error) {
    console.error(`Error: ${error}`);
  }

}
main();

👨‍💻 Node.JS Code for solve reCaptcha v2 with proxy

Here's a Node.JS sample script to accomplish the task:

const axios = require('axios');

const PAGE_URL = ""; // Replace with your Website
const SITE_KEY = ""; // Replace with your Website
const CLIENT_KEY = "";  // Replace with your CAPSOLVER API Key
const PROXY =  "https://username:password@host:port";

async function createTask(payload) {
  try {
    const res = await axios.post('https://api.capsolver.com/createTask', {
      clientKey: CLIENT_KEY,
      task: payload
    });
    return res.data;
  } catch (error) {
    console.error(error);
  }
}
async function getTaskResult(taskId) {
    try {
        success = false;
        while(success == false){

            await sleep(1000);
        console.log("Getting task result for task ID: " + taskId);
      const res = await axios.post('https://api.capsolver.com/getTaskResult', {
        clientKey: CLIENT_KEY,
        taskId: taskId
      });
      if( res.data.status == "ready") {
        success = true;
        console.log(res.data)
        return res.data;
      }
    }
  
    } catch (error) {
      console.error(error);
      return null;
    }
  }
  

async function solveReCaptcha(pageURL, sitekey) {
  const taskPayload = {
    type: "ReCaptchaV2Task",
    websiteURL: pageURL,
    websiteKey: sitekey,
    proxy: PROXY
  };
  const taskData = await createTask(taskPayload);
  return await getTaskResult(taskData.taskId);
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
  try {
   
      const response = await solveReCaptcha(PAGE_URL, SITE_KEY );
      console.log(`Received token: ${response.solution.gRecaptchaResponse}`);
        
    }
catch (error) {
    console.error(`Error: ${error}`);
  }

}
main();

⚠️ Change these variables

  • PROXY: Change to your proxy, only if you use ReCaptchaV2Task.
  • CLIENT_KEY: Obtain your API key from the Capsolver Dashboard.
  • PAGE_URL: Replace with the URL of the website for which you wish to solve hCaptcha
  • SITE_KEY: Replace with the site key of the page with hcaptcha

👀 More information

More

How identify and obtain reCaptcha 's' data
How identify and obtain reCaptcha 's' data

Learn to identify and obtain reCaptcha 's' data for effective captcha solving. Follow our step-by-step guide on using Capsolver's tools and techniques.

reCAPTCHA

21-Nov-2023

What is reCaptcha v3 and how to solve with the highest human score 0.9
What is reCaptcha v3 and how to solve with the highest human score 0.9

In this article we will teach you what reCaptcha v3 is and how to easily solve the reCaptcha v3 with high score (0.7-0.9) using CapSolver.

reCAPTCHA

09-Nov-2023

Wie man jede Version von reCAPTCHA Enterprise v2, v2 invisible, v3, v3 enterprise mit einer Punktzahl von 0,9 umgeht/löst
Wie man jede Version von reCAPTCHA Enterprise v2, v2 invisible, v3, v3 enterprise mit einer Punktzahl von 0,9 umgeht/löst

Das reCAPTCHA Token erhält immer eine ungültige Antwort? Diese Situation tritt normalerweise auf, wenn reCAPTCHA v2 die Enterprise-Version ist, die normalerweise einen 's'-Parameter hat, oder reCAPTCHA v3 Enterprise-Version, die eine hohe Punktzahl von 0.7 oder höher erfordert. Jetzt kann CapSolver dieses Problem perfekt lösen.

reCAPTCHA

09-Nov-2023

How to Solve "Unusual Traffic from Your Computer Network"
How to Solve "Unusual Traffic from Your Computer Network"

Struggling with 'Unusual traffic from your computer network' errors on Google? Our guide explains the triggers and offers solutions to solve captchas, including tips and a look at how CAPSOLVER.COM can streamline your browsing experience by automatically resolving these interruptions.

reCAPTCHA

08-Nov-2023

Làm thế nào để giải quyết reCaptcha v3 và nhận được điểm giống như con người (>0,7-0,9)
Làm cách nào để giải quyết reCaptcha v3 và đạt điểm cao (>0.7–0.9)

Trong hướng dẫn sắp tới, chúng tôi sẽ làm sáng tỏ quá trình dễ dàng vượt qua reCaptcha v3 và đạt được điểm số giống như con người bằng cách sử dụng một công cụ sáng tạo có tên CapSolver. Đối với giáo dân, reCaptcha v3 là một giải pháp bảo mật hiện đại được cung cấp bởi Google được thiết kế để bảo vệ các trang web khỏi bot mà không cần sự tương tác của người dùng. Không giống như các phiên bản trước, reCaptcha v3 trả về một điểm dự đoán liệu tương tác đến từ con người hay robot, thay vì đưa ra một thách thức cần được giải quyết. Mặc dù trực quan và hiệu quả, công cụ đôi khi đặt ra những thách thức không lường trước được cho người dùng hợp pháp, ảnh hưởng đến sự trôi chảy của trải nghiệm kỹ thuật số của họ. Đây là nơi CapSolver hoạt động. CapSolver là một công cụ phức tạp được thiết kế để giúp người dùng duyệt reCaptcha v3 liền mạch. Nó được thiết kế đặc biệt để tương tác với reCaptcha theo cách bắt chước hành vi của con người, do đó đảm bảo điểm số giống như con người. Với CapSolver, bạn có thể đảm bảo trải nghiệm trực tuyến mượt mà hơn, không bị chậm trễ hoặc gián đoạn thường liên quan đến CAPTCHA. Với bài viết này, chúng tôi sẽ hướng dẫn bạn từng bước phá vỡ các thuật ngữ kỹ thuật phức tạp thành các khái niệm dễ hiểu. Chúng tôi muốn cung cấp một cái nhìn toàn diện về cách sử dụng CapSolver hiệu quả, đảm bảo rằng bạn có thể vượt qua reCaptcha v3 tương đối dễ dàng. Hãy nhớ rằng hướng dẫn này được thiết kế để giúp người dùng hợp pháp điều hướng thông suốt reCaptcha v3 và không bao giờ hỗ trợ bất kỳ hình thức hoạt động phi đạo đức hoặc nỗ lực làm suy yếu an ninh của trang web. Vì vậy, cho dù bạn là một navigator chuyên nghiệp trong lĩnh vực kỹ thuật số hay người dùng Internet trung bình, biết reCaptcha v3 và học cách sử dụng các công cụ như CapSolver có thể tăng cường đáng kể khả năng điều hướng trực tuyến của bạn. Đi sâu vào chủ đề hấp dẫn này với chúng tôi để cung cấp cho bạn những kỹ năng vô giá trong hành trình kỹ thuật số của bạn.

reCAPTCHA

07-Nov-2023

Solve reCaptcha v2 invisible - Explained
Solve reCaptcha v2 invisible - Explained

Master solving reCaptcha v2 invisible with Capsolver: Precise identification and effective resolution for optimizing your automated processes

reCAPTCHA

06-Nov-2023