Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在没有提交按钮的情况下提交谷歌验证码?_Python_Selenium_Selenium Chromedriver_Recaptcha_2captcha - Fatal编程技术网

Python 如何在没有提交按钮的情况下提交谷歌验证码?

Python 如何在没有提交按钮的情况下提交谷歌验证码?,python,selenium,selenium-chromedriver,recaptcha,2captcha,Python,Selenium,Selenium Chromedriver,Recaptcha,2captcha,我正在使用python和selenium编写一个自动化脚本,但最后一步有问题,因为前面的步骤在captcha下有submit按钮,所以表单被提交了。我在考虑直接加载对网站的验证码响应,但我没有找到任何方法来做到这一点 我正在使用2captcha自动解析 我找到了这段提交验证码的视频,我已经查看了代码,但我不知道它是否适用于我的代码 这是我与这个问题相关的代码的一部分 def captchaHome(): driver.execute_script('var element=docume

我正在使用python和selenium编写一个自动化脚本,但最后一步有问题,因为前面的步骤在captcha下有submit按钮,所以表单被提交了。我在考虑直接加载对网站的验证码响应,但我没有找到任何方法来做到这一点

我正在使用2captcha自动解析

我找到了这段提交验证码的视频,我已经查看了代码,但我不知道它是否适用于我的代码

这是我与这个问题相关的代码的一部分

def captchaHome():
    driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
    service_key = 'xxxxxxxxxxxxxxxxxxxxxx'  # 2captcha service key
    google_site_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'  # reCAPTCHAのdata-sitekey
    pageurl = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl
    resp = requests.get(url)
    if resp.text[0:2] != 'OK':
        quit('Service error. Error code:' + resp.text)
    captcha_id = resp.text[3:]
    fetch_url = "http://2captcha.com/res.php?key=" + service_key + "&action=get&id=" + captcha_id

    for i in range(1, 10):
        time.sleep(10)  # wait 10 sec.
        resp = requests.get(fetch_url)
        if resp.text[0:2] == 'OK':
            break
    print('Google response token: ', resp.text[3:])
    return resp.text[3:]

capHome = captchaHome()
driver.find_element_by_id('g-recaptcha-response').send_keys(capHome)

这是我想提交的网站代码


          function show(classNames) {
            classNames.forEach(function(className) {
              document.querySelector(className).classList.remove('hidden');
            });
          }

          function hide(classNames) {
            classNames.forEach(function(className) {
              document.querySelector(className).classList.add('hidden');
            });
          }

          function showAnimation() {
            hide(['.challenge', '.error', '.success']);
            show(['.redeem', '.animation']);
          }

          function showSuccess() {
            hide(['.challenge', '.error']);
            show(['.redeem', '.success', '.animation']);
          }

          function showError() {
            hide(['.challenge', '.success', '.animation']);
            show(['.redeem', '.error']);
          }

          // used in data-callback
          function redemptionValidation(captchaResponse) {
            showAnimation();

            function reqListener() {
              if (this.status >= 200 && this.status < 400) {
                var redirectUrl = this.responseText;
                showSuccess();
                setTimeout(function() {
                  window.location.replace(redirectUrl);
                }, 3000);
              } else {
                showError();
              }
            }

            function reqErrListener() {
              showError();
            }


            var req = new XMLHttpRequest();
            req.addEventListener('load', reqListener);
            req.addEventListener('error', reqErrListener);
            req.open('POST', '/googlehome/redeem/getcode/');
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            req.send('g-recaptcha-response=' + encodeURIComponent(captchaResponse));
          }
然后用selenium找到它并单击()

尝试使用send_键(key.RETURN)而不是单击submit按钮

编辑:
将返回键发送到代码中通常单击submit按钮的位置应该会产生相同的结果。

我用这个解决了这个问题

driver.execute_script("redemptionValidation(\"" + capHome + "\")")

你能补充一下相关的解释吗?谢谢我面临着类似的问题。找不到任何脚本。
driver.execute_script("redemptionValidation(\"" + capHome + "\")")