1717import sys
1818
1919import httpx
20+
2021try :
2122 from dotenv import load_dotenv
2223except ModuleNotFoundError as exc :
23- if exc .name != ' dotenv' :
24+ if exc .name != " dotenv" :
2425 raise
2526 load_dotenv = None
2627
2728repo_root = os .path .dirname (os .path .dirname (os .path .dirname (os .path .realpath (__file__ ))))
2829sys .path .append (repo_root )
2930if load_dotenv is not None :
30- load_dotenv (os .path .join (repo_root , ' .env' ))
31+ load_dotenv (os .path .join (repo_root , " .env" ))
3132
3233from captcha_solver_api import AsyncCaptchaClient
33- from captcha_solver_api .tasks import GeeTestTaskProxyless , GeeTestTask
34+ from captcha_solver_api .tasks import GeeTestTask , GeeTestTaskProxyless
3435
35- api_key = os .getenv (' CAPTCHA_API_KEY' , ' YOUR_API_KEY' )
36+ api_key = os .getenv (" CAPTCHA_API_KEY" , " YOUR_API_KEY" )
3637
3738# GeeTest tasks may take longer. Increase timeout if needed.
3839solver = AsyncCaptchaClient (api_key , timeout = 300 , polling_interval = 10 )
@@ -48,43 +49,47 @@ async def main():
4849 # In production, extract this from the page's initGeetest call or network requests.
4950 # "target-site.com" is a placeholder -- point this at your real target before running.
5051 async with httpx .AsyncClient () as client :
51- resp = await client .get (' https://target-site.com/path/to/geetest/init' , timeout = 30 )
52- challenge = resp .json ()[' challenge' ]
52+ resp = await client .get (" https://target-site.com/path/to/geetest/init" , timeout = 30 )
53+ challenge = resp .json ()[" challenge" ]
5354
5455 # --- Proxyless example ---
5556 # Solves GeeTest v3 without a proxy.
5657 # v3 is the default version, so the version field can be omitted.
5758 try :
58- result = await solver .solve (GeeTestTaskProxyless (
59- websiteURL = 'https://example.com/login' , # Full URL of the page with GeeTest
60- gt = 'f2ae6cadcf7886856696c46d84d109d1' , # Public key of the GeeTest widget
61- challenge = challenge , # Session-specific value, must be fresh
62- # Optional fields
63- # geetestApiServerSubdomain='api-na.geetest.com', # Custom API subdomain
64- # initParameters={...}, # Extra params from initGeetest call
65- # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent
66- ))
59+ result = await solver .solve (
60+ GeeTestTaskProxyless (
61+ websiteURL = "https://example.com/login" , # Full URL of the page with GeeTest
62+ gt = "f2ae6cadcf7886856696c46d84d109d1" , # Public key of the GeeTest widget
63+ challenge = challenge , # Session-specific value, must be fresh
64+ # Optional fields
65+ # geetestApiServerSubdomain='api-na.geetest.com', # Custom API subdomain
66+ # initParameters={...}, # Extra params from initGeetest call
67+ # userAgent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...', # Browser User-Agent
68+ )
69+ )
6770 # Solution contains {"challenge": "...", "validate": "...", "seccode": "..."}
6871 # Pass solution.validate and solution.seccode to the page's GeeTest callback.
69- print (' result: ' + str (result ))
72+ print (" result: " + str (result ))
7073 except Exception as e :
7174 sys .exit (e )
7275
7376 # --- With proxy example ---
7477 # Solves GeeTest v3 through your own proxy.
7578 try :
76- result = await solver .solve (GeeTestTask (
77- websiteURL = 'https://example.com/login' , # Full URL of the page with GeeTest
78- gt = 'f2ae6cadcf7886856696c46d84d109d1' , # Public key of the GeeTest widget
79- challenge = challenge , # Session-specific value, must be fresh
80- # --- Proxy parameters (replace with your own -- these are placeholders) ---
81- proxyType = 'http' , # http, socks4, or socks5
82- proxyAddress = '1.2.3.4' , # Proxy IP address
83- proxyPort = 8080 , # Proxy port
84- proxyLogin = 'user' , # Login for proxy authorization (optional)
85- proxyPassword = 'password' , # Password for proxy authorization (optional)
86- ))
87- print ('result: ' + str (result ))
79+ result = await solver .solve (
80+ GeeTestTask (
81+ websiteURL = "https://example.com/login" , # Full URL of the page with GeeTest
82+ gt = "f2ae6cadcf7886856696c46d84d109d1" , # Public key of the GeeTest widget
83+ challenge = challenge , # Session-specific value, must be fresh
84+ # --- Proxy parameters (replace with your own -- these are placeholders) ---
85+ proxyType = "http" , # http, socks4, or socks5
86+ proxyAddress = "1.2.3.4" , # Proxy IP address
87+ proxyPort = 8080 , # Proxy port
88+ proxyLogin = "user" , # Login for proxy authorization (optional)
89+ proxyPassword = "password" , # Password for proxy authorization (optional)
90+ )
91+ )
92+ print ("result: " + str (result ))
8893 except Exception as e :
8994 sys .exit (e )
9095
0 commit comments