【问题标题】:Python + Selenium + 2CaptchaPython + Selenium + 2Captcha
【发布时间】:2020-02-03 03:10:24
【问题描述】:

我正在尝试使用 2captcha 服务解决网站中的重新验证码问题,但总是向我返回错误:

Traceback(最近一次调用最后一次):文件 “C:\Users\pablo\Desktop\selenium\MercBitk.py”,第 48 行,在 GChrome.find_element_by_xpath("//*[@id='g-recaptcha-response']").send_keys(resp.text[3:])

文件 "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py", 第 479 行,在 send_keys 中 “值”:keys_to_typing(value)})
文件“C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py”, 第 633 行,在 _execute return self._parent.execute(command, params)
文件“C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, 第 321 行,在执行中 self.error_handler.check_response(响应)
文件 "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", 第 242 行,在 check_response 中 raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.ElementNotInteractableException:消息: 元素不可交互(会话信息:chrome=77.0.3865.90)

但我没有找到我哪里出错了...... 代码正确插入CPF和密码,代码发送验证码并正确接收代码到2captcha站点,但无法发送...

代码是:

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import requests
import getpass
import json
from selenium.webdriver.support.ui import Select

from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait

GChrome = webdriver.Chrome()
GChrome.get('https://www.mercadobitcoin.com.br/conta/login/')

box_login = GChrome.find_element_by_name('cpfcnpj')
box_login.send_keys('my_cpf')
box_pass = GChrome.find_element_by_name('password')
box_pass.send_keys('my_pass')

box_pass.send_keys(Keys.ENTER)

# 2Captcha service
service_key = 'fa...d4' # 2captcha service key 
google_site_key = '6LfIxCoUAAAAAEEW7DQK_gj3pzzeJz82dTW_SMNH' 
pageurl = 'https://www.mercadobitcoin.com.br/conta/login/' 
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(5) # wait 5 sec.
    resp = requests.get(fetch_url)
    if resp.text[0:2] == 'OK':
        break 

GChrome.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')

GChrome.find_element_by_xpath("//*[@id='g-recaptcha-response']").send_keys(resp.text[3:]) #ERROR HERE <<<<<<

有人可以帮我吗?我已经尝试了3天解决这个错误

【问题讨论】:

    标签: python selenium selenium-webdriver recaptcha 2captcha


    【解决方案1】:

    继续 pguardiario 出色的响应,你们中的许多人都注意到它填充了文本框但它没有发送但是由于我们发现自己的文本框现在可见的情况,只需提交响应就足够了(它为我做了):

    driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
    driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = arguments[0]', resp.text[3:])
    driver.find_element_by_id("g-recaptcha-response").submit()
    

    【讨论】:

      【解决方案2】:

      pguardiario 提供的调用之后,执行以下操作:

      driver.execute_script("""
        onSubmit(arguments[0])
      """, resp.text[3:])
      

      这是使用回调函数的不可见的recaptcha,在您的案例中函数名称是onSubmit。

      【讨论】:

        【解决方案3】:

        我认为这是因为它是隐藏的。试试这样:

        driver.execute_script("""
          document.getElementById("g-recaptcha-response").innerHTML = arguments[0]
        """, resp.text[3:])
        

        在您的情况下替换 GChrome 的驱动程序。

        【讨论】:

        • 字面上同样的错误=\(我在google chrome和firefox上试过)
        • 在谷歌浏览器中,错误是一样的,在 Firefox 中它看起来像接受 .send_keys 但它就像它不“发送”,因为它转到除了站点之外的下一行代码不退出验证码
        • 下一个代码是Wait_reCaptcha = wait.until(ec.visibility_of_element_located((By.XPATH, '//*[@title="Comprar Bitcoins"]'))),错误是超时(但从超时只是因为它不是从recaptcha中出来,就像他会写答案但不发送)
        • 不,它不会给出同样的错误。最后一个超时,因为它永远不可见。
        • 对不起,没错,在 Firefox 和 Chrome 中都是同样的错误。就好像 selenium 写了代码响应但不发送它一样
        猜你喜欢
        • 2021-04-10
        • 2021-10-22
        • 1970-01-01
        • 2020-11-24
        • 2020-09-19
        • 2021-02-04
        • 2020-01-18
        • 1970-01-01
        • 2019-07-22
        相关资源
        最近更新 更多