Blog
How to solve Cloudflare Turnstile Captcha with Python

How to solve Cloudflare Turnstile Captcha with Python

Logo of Capsolver

CapSolver Blogger

How to use capsolver

13-May-2024

Solve Cloudflare with Python, Cloudflare python solver

What is Cloudflare Turnstile

Cloudflare Turnstile is a free tool to replace CAPTCHAs
Turnstile delivers frustration-free, CAPTCHA-free web experiences to website visitors - with just a simple snippet of free code. Moreover, Turnstile stops abuse and confirms visitors are real without the data privacy concerns or awful user experience of CAPTCHAs.

How to identify Cloudflare Turnstile Captcha

🛠️ Solving cloudflare turnstile captcha

⚙️ Prerequisites

🤖 Step 1: Install Necessary Packages

Execute the following commands to install the required packages:

pip install requests

👨‍💻 Step 2: Python Code for solve Cloudflare Turnstile Captcha

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

import time
import requests

CAPSOLVER_API_KEY = "api key"
PAGE_URL = "url"
WEBSITE_KEY = "site key"

def solvecf(metadata_action=None, metadata_cdata=None):
    url = "https://api.capsolver.com/createTask"
    task = {
        "type": "AntiTurnstileTaskProxyLess",
        "websiteURL": PAGE_URL,
        "websiteKey": WEBSITE_KEY,
    }
    if metadata_action or metadata_cdata:
        task["metadata"] = {}
        if metadata_action:
            task["metadata"]["action"] = metadata_action
        if metadata_cdata:
            task["metadata"]["cdata"] = metadata_cdata
    data = {
        "clientKey": CAPSOLVER_API_KEY,
        "task": task
    }
    response_data = requests.post(url, json=data).json()
    print(response_data)
    return response_data['taskId']


def solutionGet(taskId):
    url = "https://api.capsolver.com/getTaskResult"
    status = ""
    while status != "ready":
        data = {"clientKey": CAPSOLVER_API_KEY, "taskId": taskId}
        response_data = requests.post(url, json=data).json()
        print(response_data)
        status = response_data.get('status', '')
        print(status)
        if status == "ready":
            return response_data['solution']

        time.sleep(2)


def main():
    
    taskId = solvecf()
    solution = solutionGet(taskId)
    if solution:
        user_agent = solution['userAgent']
        token = solution['token']

    print("User_Agent:", user_agent)
    print("Solved Turnstile Captcha, token:", token)

  
if __name__ == "__main__":
    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

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