CAPSOLVER
Blog
How to solve Cloudflare Turnstile Captcha with NodeJS

How to solve Cloudflare Turnstile Captcha with NodeJS

Logo of Capsolver

Ethan Collins

Pattern Recognition Specialist

13-May-2024

Solve Cloudflare Captcha with Nodejs, Cloudflare Nodejs solver

Cloudflare Turnstile Overview

Cloudflare Turnstile offers a free solution for replacing traditional CAPTCHAs, providing a hassle-free web experience through a simple code snippet. It ensures that visitors are genuine and prevents abuse without the data privacy issues or poor user experience associated with conventional CAPTCHAs.

Identifying Cloudflare Turnstile CAPTCHAs

  • Non-Interactive Challenge: The process runs without user interaction. Example: Non-Interactive Test

  • Minimal Interactive Challenge: This may involve simple actions like clicking a button if the system suspects the visitor might be a bot. Example: Managed Test
    Cloudflare Turnstile Captcha

  • Invisible Challenge: The challenge operates unseen, loading discreetly within the HTML of the webpage. Example: Invisible Test

šŸ› ļø Solving cloudflare turnstile captcha

āš™ļø Prerequisites

  • NodeJs installed
  • Capsolver API key

šŸ¤– Step 1: Install Necessary Packages

Execute the following commands to install the required packages:

npm i axios

šŸ‘Øā€šŸ’» Step 2: NodeJS Code for solve Cloudflare Turnstile Captcha

Here's a Python sample script to accomplish the task:

const axios = require('axios');
const CAPSOLVER_API_KEY = "your api key";
const PAGE_URL = "site ";
const WEBSITE_KEY = "site key";

function solvecf(metadata_action = null, metadata_cdata = null) {
    const url = "https://api.capsolver.com/createTask";
    const task = {
        type: "AntiTurnstileTaskProxyLess",
        websiteURL: PAGE_URL,
        websiteKey: WEBSITE_KEY,
    };
    if (metadata_action || metadata_cdata) {
        task.metadata = {};
        if (metadata_action) {
            task.metadata.action = metadata_action;
        }
        if (metadata_cdata) {
            task.metadata.cdata = metadata_cdata;
        }
    }
    const data = {
        clientKey: CAPSOLVER_API_KEY,
        task: task
    };
    return axios.post(url, data)
        .then(response => {
            console.log(response.data);
            return response.data.taskId;
        });
}

function solutionGet(taskId) {
    const url = "https://api.capsolver.com/getTaskResult";
    let status = "";
    const checkStatus = () => {
        const data = { clientKey: CAPSOLVER_API_KEY, taskId: taskId };
        return axios.post(url, data)
            .then(response => {
                console.log(response.data);
                status = response.data.status || "";
                console.log(status);
                if (status === "ready") {
                    return response.data.solution;
                }
                return new Promise(resolve => setTimeout(resolve, 2000)).then(checkStatus);
            });
    };
    return checkStatus();
}

async function main() {
    try {
        const taskId = await solvecf();
        const solution = await solutionGet(taskId);
        if (solution) {
            const user_agent = solution.userAgent;
            const token = solution.token;
            console.log("User_Agent:", user_agent);
            console.log("Solved Turnstile Captcha, token:", token);
        }
    } catch (error) {
        console.error("Error in CAPSOLVER API interaction:", error);
    }
}

main();

āš ļø Change these variables

  • CAPSOLVER_API_KEY: Obtain your API key from the Capsolver Dashboard.
  • PAGE_URL: Replace with the URL of the website for which you wish to solve the CloudFlare Turnstile Captcha.
  • WEBSITE_KEY: Replace with the site key of the website

What the CloudFlare Turnstile Captcha Looks Like

Cloudflare Turnstile Captcha

Meanwhile, if you'd like to test your scripts for bot characteristics, BrowserScan's Bot Detection tool can help you identify and refine bot-like behavior in your scripts.

More

How to Automate Cloudflare Turnstile Solve for Web Crawling
How to Automate Cloudflare Turnstile Solve for Web Crawling

We will explore strategies for handling Cloudflare Turnstile CAPTCHA in web crawling and discuss techniques to automate its solution using Puppeteer and CapSolver in Python.

Cloudflare
Logo of Capsolver

Lucas Mitchell

27-Sep-2024

How to Use C# to Solve Cloudflare Turnstile CAPTCHA Challenges
How to Use C# to Solve Cloudflare Turnstile CAPTCHA Challenges

You'll know how to easily solve Cloudflare Turnstile's CAPTCHA challenge using C#, and want to know the specifics? Let's go!

Cloudflare
Logo of Capsolver

Lucas Mitchell

18-Sep-2024

How to Solve Cloudflare with Playwright in 2024
How to Solve Cloudflare with Playwright in 2024

Learn how to solve Cloudflare Turnstile using Playwright and CapSolver in 2024 for seamless web automation.

Cloudflare
Logo of Capsolver

Ethan Collins

12-Sep-2024

How to Solve Cloudflare with Puppeteer
How to Solve Cloudflare with Puppeteer

Learn how to effectively solve Cloudflare's security challenges using Puppeteer and CapSolver. This guide provides a step-by-step approach to bypass JavaScript checks and CAPTCHAs, enabling seamless web scraping and automation on Cloudflare-protected websites.

Cloudflare
Logo of Capsolver

Lucas Mitchell

26-Aug-2024

Understanding Cloudflare 1010 Error and How to Solve It
Understanding Cloudflare 1010 Error and How to Solve It

Learn how to resolve the Cloudflare 1010 error, commonly known as "Access Denied: Bad Bot." Understand the causes behind this error and discover practical solutions, including CapSolver integration, to bypass Cloudflare's security checks and ensure seamless access to websites.

Cloudflare
Logo of Capsolver

Lucas Mitchell

22-Aug-2024

How to solve cloudflare | Using Puppeteer Node.JS
How to solve cloudflare | Using Puppeteer Node.JS

We will explore how to effectively solve Cloudflare like Turnstile by using Puppeteer and Node.js and the help from Captcha solver

Cloudflare
Logo of Capsolver

Rajinder Singh

20-Aug-2024