Blog
How to solve Cloudflare Turnstile Captcha with NodeJS

How to solve Cloudflare Turnstile Captcha with NodeJS

Logo of Capsolver

CapSolver Blogger

How to use capsolver

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

Cloudflare 403 forbidden
How to Solve Cloudflare 403 Forbidden Error and 522/1020/1010/1015/1012

Cloudflare is a widely-used content delivery network (CDN) and security service that helps websites mitigate various threats, including DDoS attacks and abusive bots...

Cloudflare

15-May-2024

Cloudflare Turnstile and Challenge
How to Solve Cloudflare Turnstile and Challenge in 2024

Approximately 20% of the websites that require scraping employ Cloudflare, a robust anti-bot protection system that can easily block your access...

Cloudflare

15-May-2024

How to solve Cloudflare Turnstile Captcha with Python
How to solve Cloudflare Turnstile Captcha with Python

In this article, we will show you how to solve cloudflare turnstile captcha with Python.

Cloudflare

13-May-2024

How to solve Cloudflare Turnstile Captcha with NodeJS
How to solve Cloudflare Turnstile Captcha with NodeJS

In this article, we will show you how to solve cloudflare turnstile captcha with NodeJS.

Cloudflare

13-May-2024

How to Solve Cloudflare when Web Scraping in 2024 | Step by Step Guide
How to Solve Cloudflare when Web Scraping in 2024 | Step by Step Guide

This blog post delves into effective techniques for solve these defenses with the help of CapSolver, a tool adept at resolving CAPTCHAs. From explaining Cloudflare's security protocols to providing practical strategies and code samples for circumventing these restrictions.

Cloudflare

07-May-2024

How to Solve Cloudflare in 2024: Solve Cloudflare Turnstile and Challenge By Using CapSolver
How to Solve Cloudflare in 2024: Solve Cloudflare Turnstile and Challenge By Using CapSolver

navigating Cloudflare's sophisticated security barriers like the Turnstile and Challenge CAPTCHA remains a critical task for many users. This blog post explores effective methods to bypass these protections using CapSolver, a tool designed for solving CAPTCHAs efficiently. Covering everything from understanding Cloudflare's security measures to practical strategies and code examples for overcoming the barriers, this guide is essential for anyone looking to access Cloudflare-protected sites without interruptions.

Cloudflare

07-May-2024