我正在用python创建硒代码来解决验证码,该验证码需要使用2captcha API单击图像“ ReCaptcha V2”。
请检查:https://2captcha.com/2captcha-api#solving_clickcaptcha
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:])