DJIGIT95
New member
I am having a code to solve Recaptcha by using python selenium, everything is working ok.
and I just want to refine it > whenever running this code, I want to make sure the js
you can see the last two items can be changed.
I just know how to inspect it manually on chrome, see the pic,
enter image description here
but how about check it by selenium? so that I can auto-apply into my code.
here is my code, a lot of code, but you can just see the final line I apply for this js element in selenium:
and I just want to refine it > whenever running this code, I want to make sure the js
elements ___grecaptcha_cfg.clients[0].I.I
is correct. this element can rotate into different values from time to time, for some examples:___grecaptcha_cfg.clients[0].J.J
___grecaptcha_cfg.clients[0].Gq.X.
___grecaptcha_cfg.clients[0].aa.l.
you can see the last two items can be changed.
I just know how to inspect it manually on chrome, see the pic,
enter image description here
but how about check it by selenium? so that I can auto-apply into my code.
here is my code, a lot of code, but you can just see the final line I apply for this js element in selenium:
Code:
# request post send to 2captcha------------------
my_request_post = rf"https://2captcha.com/in.php" \
rf"?key={my_api}" \
rf"&method={method}" \
rf"&invisible=1" \
rf"&googlekey={data_sitekey}" \
rf"&pageurl={my_url}"
# request ticket from recaptcha v2-----------------------
startime = time.time()
print('start request to 2captcha')
resp = requests.get(my_request_post)
if resp.text[0:2] != 'OK':
quit('Service error. Error code:' + resp.text)
print(f'return captcha_id: {resp.text}')
captcha_id = resp.text[3:] # get the ticket
# the request post with ticket ask for solving recaptcha----------------------
request_2captcha = rf'https://2captcha.com/res.php' \
rf'?key={my_api}' \
rf'&action=get' \
rf'&json=0' \
rf'&id={captcha_id}'
# as offical document suggested, wait for 15 secs-----------------
print('wait for 15 sec')
time.sleep(15)
for i in range(1, 50):
time.sleep(5) # wait 5 sec
resp = requests.get(request_2captcha)
print(f'attempt request cycle: {i} | resp.text: {resp.text}')
if resp.text[0:2] == 'OK':
break
# vialidation code that apply back to the site----------------------------
result = resp.text[3:]
driver.execute_script(f'document.getElementById("g-recaptcha-response").innerHTML = "{result}"')
driver.execute_script(f"___grecaptcha_cfg.clients[0].I.I.callback = '{result}'")