Home:ALL Converter>No callback function and button submit 2Captcha and Selenium

No callback function and button submit 2Captcha and Selenium

Ask Time:2020-01-16T16:31:34         Author:Majkel36

Json Formatter

I'm trying to learn how to write programs using python and combining selenium with the 2captcha API. Working on code from another topic that obviously works. I was able to learn this a little. below is the code I'm learning

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import requests


GChrome=webdriver.Firefox(executable_path="C:\driverswebs\geckodriver-v0.26.0-win64\geckodriver.exe")
GChrome.get('https://www.mercadobitcoin.com.br/conta/login/')

box_login = GChrome.find_element_by_name('cpfcnpj')
box_login.send_keys('my_cpf')
box_pass = GChrome.find_element_by_name('password')
box_pass.send_keys('my_pass')

box_pass.send_keys(Keys.ENTER)


# 2Captcha service
service_key = '7dccd1' # 2captcha service key
google_site_key = '6LfIxCoUAAAAAEEW7DQK_gj3pzzeJz82dTW_SMNH'
pageurl = 'https://www.mercadobitcoin.com.br/conta/login/'
url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl
resp = requests.get(url)

if resp.text[0:2] != 'OK':
    quit('Service error. Error code:' + resp.text)
captcha_id = resp.text[3:]

fetch_url = "http://2captcha.com/res.php?key="+ service_key + "&action=get&id=" + captcha_id

for i in range(1, 10):
    time.sleep(5) # wait 5 sec.
    resp = requests.get(fetch_url)
    if resp.text[0:2] == 'OK':
        break

GChrome.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')

GChrome.execute_script("""
  document.getElementById("g-recaptcha-response").innerHTML = arguments[0]
""", resp.text[3:])

GChrome.execute_script("""
  onSubmit(arguments[0])
""", resp.text[3:])

the above code works but if we have the onSubbmit button which has callback functions what if we don't have them ? According to the 2Captcha API, when there is no button, find the ___grecaptcha_cfg.clients[0] .aa.l.callback parameter in the code and refer to it.

Only in my case there is no Callback parameter and how to send the received tokken in this case? below the code fragmet ___grecaptcha_cfg.clients[0]

enter image description here

I will be grateful for any help :)

Author:Majkel36,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/59765598/no-callback-function-and-button-submit-2captcha-and-selenium
yy