1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| from undetected_chromedriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from twocaptcha import TwoCaptcha
API_key = ""
chrome_driver_path = ""
sitekey = "0x4AAAAAAABKK-fmValRCMjW"
def search():
url = "https://dl-protect.link/f271b5f1?fn=TUlDSEFFTCBDT05ORUxMWSAtIEwnw4lUT0lMRSBEVSBEw4lTRVJUIC0gSEFSUlkgQk9TQ0ggMjQgW0F1ZGlvQm9va3Nd&rl=e2"
# Initialize the WebDriver
chrome_options = ChromeOptions()
chrome_options.add_argument(
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
)
chrome_options.headless = False
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--lang=en-US,en;q=0.9")
chrome_options.add_argument("--window-size=1920,1080")
driver = Chrome(options=chrome_options)
try:
inject_turnstile_script(driver)
captcha_id, token = solve_turnstile(API_key, sitekey, url)
if captcha_id:
driver.get(url)
time.sleep(5)
handle_turnstile_callback(driver, token)
finally:
driver.quit()
def solve_turnstile(api_key, sitekey, url):
solver = TwoCaptcha(api_key)
try:
result = solver.turnstile(
sitekey=sitekey,
url=url,
submit_api_url="http://api.2captcha.com/res.php",
)
if "captchaId" in result and "code" in result:
captcha_id = result["captchaId"]
code = result["code"]
print(f"Solved FunCaptcha. Captcha ID: {captcha_id}, Code: {code}")
return captcha_id, code
else:
print(f"Unexpected response format: {result}")
return None
except Exception as e:
print(f"Error solving turnstile: {e}")
return None
def handle_turnstile_callback(driver, token):
callback_script = f"window.tsCallback('{token}')"
driver.execute_script(callback_script)
def inject_turnstile_script(driver):
# Inject the provided JavaScript code into the page
script = """
const i = setInterval(()=>{
if (window.turnstile) {
clearInterval(i)
window.turnstile.render = (a, b) => {
let p = {
type: "TurnstileTaskProxyless",
websiteKey: b.sitekey,
websiteURL: window.location.href,
data: b.cData,
pagedata: b.chlPageData,
action: b.action,
userAgent: navigator.userAgent
}
console.log(JSON.stringify(p))
window.tsCallback = b.callback
return 'foo'
}
}
}, 10)
"""
driver.execute_script(script)
def main():
search()
if __name__ == "__main__":
main() |
Partager