python - 实现 2captcha,python selenium 的问题
问题描述
我在 python selenium 中实现 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)
解决方案
那是请求库的 2Captcha 指南,而不是 selenium,可能它不适用于 selenium,尝试检查此页面,2captcha API + selenium
推荐阅读
- twig - Zikula CMS -- 查找用户属性
- reactjs - 使用酶时如何从路由器模拟位置
- pointers - 具有可分配或指针属性的无限多态虚拟参数?
- java - 如何在与正则表达式模式不匹配的字符串中查找字符
- cmake - 是否可以将 Diab 与 CMake 一起使用?
- c# - 使用自动映射器将计算字段添加到 linq 投影
- go - 在golang中使用for循环来反转字符串效率低吗?
- floating-point - 如果浮点数有时可能不准确,程序员为什么还要使用它们呢?
- java - 如何测试网页上按日期排序是否正常
- vb.net - DKIM 在 vb.net 中使用 MimeKit 签署电子邮件