Python +硒+ 2Captcha [英] Python + Selenium + 2Captcha
问题描述
我正在尝试使用2captcha服务来解决网站中的重新验证码问题,但始终会向我返回错误:
I'm trying solve re-captcha in a site using 2captcha service, but always returns to me the error:
回溯(最近通话最近):文件 "C:\ Users \ pablo \ Desktop \ selenium \ MercBitk.py",第48行,在 GChrome.find_element_by_xpath("//* [@ id ='g-recaptcha-response']").send_keys(resp.text [3:])
Traceback (most recent call last): File "C:\Users\pablo\Desktop\selenium\MercBitk.py", line 48, in 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",
_execute中的第633行
返回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中
引发exception_class(消息,屏幕,堆栈跟踪)
File
"C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException:消息: 元素不可交互(会话信息:chrome = 77.0.3865.90)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=77.0.3865.90)
但是我没有发现我要去哪里错... 该代码正确地插入了CPF和密码,该代码也发送了验证码,并且也正确地将代码接收到了2captcha站点,但是无法发送...
but i'm not finding where am i going wrong ... The code insert the CPF and Password correctly, the code send the captcha and receive the code to 2captcha site correctly too, but can't send it...
代码是:
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天来解决此错误
Someone can help-me, please? I've been trying for 3 days solve this error
推荐答案
在 pguardiario 提供的呼叫之后,执行以下操作:
After the call provided by pguardiario do the following:
driver.execute_script("""
onSubmit(arguments[0])
""", resp.text[3:])
这是一个使用回调函数的隐式Recaptcha,在您的情况下,该函数的名称为onSubmit.
That's invisible recaptcha that use a callback function and the function name in your case is onSubmit.
这篇关于Python +硒+ 2Captcha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!