Sep-12-2024, 11:14 AM
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:
Thanks.
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.
