-1

Here is my code.

while True:

        username_box = self.driver.find_element_by_xpath(
            '//*[@id="snapname"]')
        username_box.send_keys('xxxx')
        sleep(2)
        age_select = Select(self.driver.find_element_by_id('age'))
        age_select.select_by_value(random.choice(age_values))
        sleep(2)
        gender_select = Select(self.driver.find_element_by_id('gender'))
        gender_select.select_by_value('female')
        sleep(2)
        add_me_btn = self.driver.find_element_by_id('submitBtn')
        add_me_btn.click()

        try:

            logout = self.driver.find_element_by_xpath(
                '//*[@id="wrap"]/div[1]/div/div[2]/ul/li/a')
            logout.click()
            sleep(2)
            logout1 = self.driver.find_element_by_xpath(
                "//*[@id='wrap']/div[1]/div/div[2]/ul/li/ul/li/a")
            logout1.click()
            sleep(5)

        except:

            service_key = 'Service key here'
            google_site_key = 'Site key here'
            pageurl = 'Page Url Here'
            url = "http://2captcha.com/in.php?key=apikeyhere&method=userrecaptcha&googlekey=sitekeyhere&pageurl=pageurlhere"
            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=apikeyhere&action=get&id=" + captcha_id
            for i in range(1, 20):
                sleep(5)
                resp = requests.get(fetch_url)
                if resp.text[0:2] == 'OK':
                    break
            print('Time to solve:', time() - start_time)
            submit_url = "urlhere"
            headers = {
                'user-agent': 'Mozilla/5.0 Chrome/52.0.2743.116 Safari/537.36'}
            payload = {
                'submit': 'submit',
                'g-recaptcha-response': resp.text[3:]
            }
            resp = requests.post(submit_url, headers=headers, data=payload)

I'm trying to solve captcha for a site. I'm using 2captcha for this job. However This code cant solve the captcha. I mean bot working until this column:

print('Time to solve:', time() - start_time)

However after that returning the begining of while loop.What can be wrong with this code?

themmfa
  • 499
  • 4
  • 15

1 Answers1

0

Have you checked if your captchas were sent to 2captcha? I mean here: https://2captcha.com/statistics/uploads And what status they have if they are there?

bobby91
  • 66
  • 2
  • yes i can check here and i can get the grecaptcha token. The only problem is i cant submit this recaptcha – themmfa Feb 24 '20 at 12:07
  • Well, if submitting token is the case, then you should find and execute the callback function. Here is the easy way: https://2captcha.com/2captcha-api#callback Or the hard way: https://captchaforum.com/threads/problem-with-invisible-recaptcha-v2-callback-function-at-mail-com-sign-up-page.56/ Briefly speaking, there can be or cannot be a submit button on the form. But anyway there also can be some request that submits answer. You want to find and reproduce this request. – bobby91 Feb 24 '20 at 16:05