【发布时间】:2019-12-16 18:52:36
【问题描述】:
我想要做的是运行一段可以同时工作的代码,但是当我加载项目时,验证码解决函数说我在函数中缺少一个参数,但我没有看看在哪里。
代码:
这段代码:
elif action_to_take == "RECAPTCHA_V2":
selenium_field = self.execute_recaptcha_v2_solver(captcha_key, url_or_field_identifier)
self.write_to_debug_file("--> SOLVING RECAPTCHA V2 ...", _filename)
然后执行:
# this function executes the ReCaptcha solver ...
def execute_recaptcha_v2_solver(self, api_key, url_or_field_identifier):
solve_recaptcha_v2 = CaptchaReCaptchaSolver.solve_recaptcha(api_key,
self.extract_data_site_key(self.driver.page_source),
url_or_field_identifier)
javascript_code = 'document.getElementById("g-recaptcha-response").innerHTML = "{}"'.format(solve_recaptcha_v2)
return self.driver.execute_script(javascript_code)
哪个运行类:
class CaptchaReCaptchaSolver(object):
# noinspection PyMethodMayBeStatic
def solve_recaptcha(self, _captcha_api_key, _site_key, _url):
print(_captcha_api_key, _site_key, _url)
""" this function solves recaptcha using 2captcha.com """
try:
# p = '127.0.0.1:6969'
# p = {'http': 'http://' + p, 'https': 'https://' + p}
# send off requests ...
s = requests.Session()
cap_id = s.post('http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}'.format(
_captcha_api_key, _site_key, _url)).text.split('|')[1]
rec_an = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(_captcha_api_key, cap_id)).text
# tell us what is going on ...
print("--> ReCAPTCHA V2 SOLVING")
print("--> SOLVING ...")
while "CAPTCHA_NOT_READY" in rec_an:
sleep(5)
rec_an = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(_captcha_api_key, cap_id)).text
rec_an = rec_an.split('|')[1]
# solved ...
print("--> " + rec_an)
print("--> SOLVED ...")
print("--> ReCAPTCHA V2 RESPONSE")
# payload ...
payload = {'key': 'value', 'gresponse': rec_an}
s.post(_url, payload)
# return ReCaptcha answer ...
return rec_an
except Exception as e:
print("2CAPTCHA.COM [ReCAPTCHA] ERROR: ", e)
错误是:
LINE 222 "selenium_field = self.execute_recaptcha_v2_solver(captcha_key, url_or_field_identifier)"): solve_recaptcha() missing 1 required positional argument: '_url'
类方法solve_recaptcha() 缺少它所说的参数,但我已经将它们打印出来并且它们都在那里,我是否缺少一些明显的东西?我看不出问题可能是什么,任何帮助将不胜感激。
【问题讨论】:
-
你正在调用类的实例方法...
标签: python python-3.x