问题描述
所以,我正在尝试使用 Selenium 登录此网站:
https://carrinho.pontofrio.com.br/Checkout?ReturnUrl=%2fSite%2fMeusPedidos.aspx#login
let money = 500;
let bike = {
cost: 300,buyBike: function(money) {
if (money >= this.cost) {
money -= this.cost;
console.log("Sold!");
} else {
console.log("You don't have enough money to buy this bike.");
}
}
}
bike.buyBike(money);
网站密钥正确,但网站不接受我的验证码回复。 所以我试着用开发者工具检查登录过程是如何发生的,它是这样的:
回调函数发生在一个我不知道它调用网站的函数之后: https://www.google.com/recaptcha/api2/userverify?k=6LfeX6kZAAAAAIhuSyQ1XRwZdOS26O-r4UJbW3y1
Post Method before callback method
而且我无法找到模拟这种 post 方法的方法,因为 Selenium 不执行 post 方法。
无论如何我可以在运行页面时收听所有 Javascript 事件(调用的代码)?
非常感谢任何帮助,谢谢!
my_driver = webdriver.Chrome(executable_path=chrome_path)
wait = webdriverwait(my_driver,20)
#Realizar o Login
def login():
my_driver.get(url)
time.sleep(4)
my_driver.find_element_by_id('Email').send_keys(usuario)
my_driver.find_element_by_id('Senha').send_keys(senha)
my_driver.find_element_by_id('Senha').send_keys(Keys.ENTER)
time.sleep(1)
solver = recaptchaV2Proxyless()
solver.set_verbose(1)
solver.set_key("")
solver.set_website_url('https://carrinho.pontofrio.com.br/Checkout?ReturnUrl=%2fSite%2fMeusPedidos.aspx#login')
solver.set_website_key("6LfeX6kZAAAAAIhuSyQ1XRwZdOS26O-r4UJbW3y1")
# solver.set_data_s('"data-s" token from Google Search results "protection"')
g_response = solver.solve_and_return_solution()
if g_response != 0:
print("g-response: " + g_response)
else:
print("task finished with error " + solver.error_code)
time.sleep(1)
my_driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "%s"' % g_response)
time.sleep(1)
my_driver.execute_script(f"callbackCaptcha('{g_response}');")
login()
解决方法
是的,我发现有两个问题,第一个是验证,我用这个选项解决了这个问题:
options.add_argument('--disable-blink-features=AutomationControlled')
另一个是当我点击登录按钮时网站正在生成一个新令牌。所以我决定先解决验证码再要求登录,使用callbackCaptcha来要求登录。