如何判断recaptcha是否已解决?

时间:2017-12-15 02:08:34

标签: selenium recaptcha

我正在使用python selenium做一些自动化工作。但是很难绕过recaptcha.So我决定手动解决recaptcha。这是大纲:

#run script
#pause
#solve recaptcha myself
#continue script

我希望我的脚本在我手动解决recaptcha之后继续运行。所以,棘手的一点是如何判断recaptcha是否已经解决。 任何想法将不胜感激!!!

1 个答案:

答案 0 :(得分:0)

所以你给了我们一份清单并期望我们为你建造它?

这不是它的工作原理。话虽这么说......我对Captcha很感兴趣。在解决验证码方面,我推荐2captcha:

import requests
from time import sleep

# Add these values
API_KEY = ''  # Your 2captcha API KEY
site_key = ''  # site-key, read the 2captcha docs on how to get this
url = 'http://somewebsite.com'  # example url
proxy = '127.0.0.1:6969'  # example proxy

proxy = {'http': 'http://' + proxy, 'https': 'https://' + proxy}

s = requests.Session()

# here we post site key to 2captcha to get captcha ID (and we parse it here too)
captcha_id = s.post("http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}".format(API_KEY, site_key, url), proxies=proxy).text.split('|')[1]
# then we parse gresponse from 2captcha response
recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id), proxies=proxy).text
print("solving ref captcha...")
while 'CAPCHA_NOT_READY' in recaptcha_answer:
    sleep(5)
    recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id), proxies=proxy).text
recaptcha_answer = recaptcha_answer.split('|')[1]

# we make the payload for the post data here, use something like mitmproxy or fiddler to see what is needed
payload = {
    'key': 'value',
    'gresponse': recaptcha_answer  # This is the response from 2captcha, which is needed for the post request to go through.
    }


# then send the post request to the url
response = s.post(url, payload, proxies=proxy)