Python Forum

Full Version: How to bypass Cloudflare checkbox challenge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

According to this manual from payed captcha resolving service
How to solve Cloudflare Turnstile

in order to resolve captcha challenge one must to provide so-called data-sitekey.
Manual also explain how to find this data-sitekey.
But the url where I try to bypass Cloudflare capctcha challenge doesn't contain data-sitekey (I checked many times) !

I contacted 2captcha support for explanations.
They returned me a link to a manual that uses more complicated approach that apparently doesn't use data-sitekey, but rather explores site response.
Here it is:
Bypassing Cloudflare Challenge with Python and Selenium
I tried also this suggestion (at least as I understood it), but it seems also failing: the params from intercept function is empty.
Here is my code:

import json
import re
import requests
from seleniumbase import Driver
from selenium.webdriver.common.by import By
import time

my_key = '1111112222233333' # this is alias, my actual code is different
url = 'url_with_captcha_challenge'

# Setting up an updated UserAgent
agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36"

# Configuring the web driver to work in headless mode
driver = Driver(uc=True, log_cdp=True, headless=True, no_sandbox=True, agent=agent, proxy=False)

# Function to intercept CAPTCHA parameters using JavaScript
def intercept(driver):
    driver.execute_script("""
    console.clear = () => console.log('Console was cleared')
    const i = setInterval(()=>{
    if (window.turnstile)
     console.log('success!!')
     {clearInterval(i)
         window.turnstile.render = (a,b) => {
          let params = {
                sitekey: b.sitekey,
                pageurl: window.location.href,
                data: b.cData,
                pagedata: b.chlPageData,
                action: b.action,
                userAgent: navigator.userAgent,
                json: 1
            }
            console.log('intercepted-params:' + JSON.stringify(params))
            window.cfCallback = b.callback
            return        } 
    }
},50)    
""")
    time.sleep(1)
    # Retrieving browser logs containing intercepted parameters
    logs = driver.get_log("browser")
    for log in logs:
        if log['level'] == 'INFO':
            if "intercepted-params:" in log["message"]:
                log_entry = log["message"].encode('utf-8').decode('unicode_escape')
                match = re.search(r'"intercepted-params:({.*?})"', log_entry)
                json_string = match.group(1)
                params = json.loads(json_string)
                return params

driver.get(url)
driver.refresh
time.sleep(5)
params = intercept(driver)
Any suggestions ?
Thanks.
i using this :
options = webdriver.ChromeOptions() 
options.add_argument("--disable-blink-features=AutomationControlled") 
options.add_experimental_option("excludeSwitches", ["enable-automation"]) 
options.add_experimental_option("useAutomationExtension", False) 
driver = webdriver.Chrome(options=options) 
some sites detect those keywords as bot detection