28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
import json, time, sys, urllib.request, urllib.parse, os
|
|
KEY=os.environ.get('TWOCAPTCHA_KEY','')
|
|
SITEKEY="0x4AAAAAABDUjQJBI2lFYkkW"
|
|
PAGE="https://www.cometapi.com/console/login"
|
|
def post(url, data):
|
|
d=urllib.parse.urlencode(data).encode()
|
|
with urllib.request.urlopen(urllib.request.Request(url, data=d, headers={'User-Agent':'Mozilla/5.0'}), timeout=40) as r:
|
|
return json.loads(r.read().decode())
|
|
def solve_turnstile(sitekey=SITEKEY, page=PAGE, tries=3):
|
|
for t in range(tries):
|
|
r=post("https://2captcha.com/in.php", {"key":KEY,"method":"turnstile","sitekey":sitekey,"pageurl":page,"json":1})
|
|
if r.get("status")!=1:
|
|
print("in err", r); time.sleep(5); continue
|
|
tid=r["request"]; print("task", tid, flush=True)
|
|
for i in range(60):
|
|
time.sleep(5)
|
|
q=urllib.request.urlopen(f"https://2captcha.com/res.php?key={KEY}&action=get&id={tid}&json=1", timeout=30).read().decode()
|
|
j=json.loads(q)
|
|
if j.get("status")==1:
|
|
return j["request"]
|
|
if j.get("request") not in ("CAPCHA_NOT_READY",):
|
|
print("res err", j); break
|
|
return None
|
|
if __name__=="__main__":
|
|
tok=solve_turnstile()
|
|
print("TOKEN_LEN", len(tok or ''))
|
|
open("ts_token.txt","w").write(tok or "")
|