How solve clickable captcha like recaptcha v2 on signup page with python and selenium?

Gabreyannya

New member
I am creating selenium code with python to solve captcha that requires clicking on images "ReCaptcha V2" with 2captcha API .

please check : https://2captcha.com/2captcha-api#solving_clickcaptcha

my first problem is get screen shot in random name and compress it to below 100Kb and send it with my http post request .
my second problem is how to simulate clicks on "OK|coordinate:x=39,y=59;x=252,y=72"
and how remove image after captcha solved ?


my code:
Code:
from selenium import webdriver
from time import sleep, time
from PIL import Image
import requests
import time

# open signup page
browser = webdriver.Chrome('D:\chromedriver')
browser.get('http://testing-ground.scraping.pro/recaptcha')
browser.maximize_window()

# click on checkbox
recaptcha = browser.find_element_by_xpath("//*[@role='presentation']"); time.sleep(3)
recaptcha.click(); time.sleep(3)

#get screenshot
browser.get_screenshot_as_file('iamcaptchaimage.jpg')

#send http request 'post'
url = 'http://2captcha.com/in.php'
files = {'file': open('iamcaptchaimage.jpg', 'rb')}
url = 'http://2captcha.com/in.php'
files = {'file': open('iamcaptchaimage.jpg', 'rb')}
data = {'key': '***', 'method': 'post','coordinatescaptcha':'1','textinstructions':'click on fire hydrant'}
resp = requests.post(url, files=files, data=data)

if resp.ok:
    captcha_id = resp.text[3:]
    print(captcha_id)
    
# send http request 'get'
fetch_url = "http://2captcha.com/res.php?key=****&action=get&id=" + captcha_id
for i in range(1, 10):
    sleep(5)  # wait 5 sec.
    resp = requests.get(fetch_url)
    if resp.text[0:2] == 'OK':
        break
print(resp.text[3:])