gpt4 book ai didi

Java/Kotlin Selenium Chromedriver 2Captcha

转载 作者:行者123 更新时间:2023-12-01 19:47:43 25 4
gpt4 key购买 nike

我正在尝试了解 2Captcha,并作为我想创建 Spotify 帐户的示例。我已经正确填写了表格,但唯一关心的是 2Captcha。我已经尝试了这里找到的各种方法,但没有一个起作用。我试过:

  • ___grecaptcha_cfg.clients[0].bL.K.callback('token');
  • window.captchaSuccessCallback(); (这是在 grecaptcha.render 方法中找到的)
  • 这是我最后的方法:
    val captcha = driver.findElement(By.id("captcha-div"))
val siteKey = captcha?.getAttribute("data-sitekey") ?: ""
println("Site key: $siteKey")

val solvedCaptcha = getCaptcha(siteKey, "2captchaKey", driver.currentUrl)
val js = driver as JavascriptExecutor
println(solvedCaptcha)
js.executeScript("document.getElementById('g-recaptcha-response').innerHTML='$solvedCaptcha';")
Thread.sleep(500)

val iframe = driver.findElement(By.xpath("//iframe[@title='recaptcha challenge']"))
println(iframe.toString())
driver.switchTo().frame(iframe)
js.executeScript("document.getElementById('recaptcha-verify-button').click();")

我使用的网址是 Here

更新的代码(仍然不起作用)添加了模拟击键,希望在检测到任何按键后可能会触发回调:

val captcha = driver.findElement(By.id("captcha-div"))
val siteKey = captcha?.getAttribute("data-sitekey") ?: ""
println("Site key: $siteKey")

val js = driver as JavascriptExecutor

val findElement = driver.findElement(By.id("g-recaptcha-response"))
js.executeScript("document.getElementById(\"g-recaptcha-response\").style.display = \"inline\";")
val solvedCaptcha = getCaptcha(siteKey, "captchaKey", driver.currentUrl)
println(solvedCaptcha)
solvedCaptcha?.forEach {
findElement.sendKeys(it.toString())
Thread.sleep(Random.nextLong(5L, 30L))
}
Thread.sleep(10000)

最佳答案

click()在与 关联的复选框上,因为所需的元素位于 <iframe> 内所以你必须:

  • 引发WebDriverWait以使所需的框架可用并切换到它
  • 引发WebDriverWait以使所需的元素可点击
  • 您可以使用以下 Locator Strategies :

    • 代码块:

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

      options = webdriver.ChromeOptions()
      options.add_argument("start-maximized")
      options.add_experimental_option("excludeSwitches", ["enable-automation"])
      options.add_experimental_option('useAutomationExtension', False)
      driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
      driver.get("https://www.spotify.com/gr/signup/")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[src^='https://www.google.com/recaptcha/api2/anchor']")))
      WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#recaptcha-anchor"))).click()
  • 浏览器快照:

reCAPTCHA

关于Java/Kotlin Selenium Chromedriver 2Captcha,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59110605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com