0

我正在尝试以 2Captcha nad 为例,我想创建一个 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();")

我使用的网址是这里

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

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)
4

2 回答 2

0

这看起来不对:

js.executeScript("document.getElementById('g-recaptcha-response').innerHTML='$solvedCaptcha';")

我不确定字符串插值在 java 中是如何工作的,但我不认为它是这样工作的。

确保已设置该值,然后单击绿色按钮,这应该可以工作。

于 2019-11-30T03:10:47.650 回答
0

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

  • 诱导WebDriverWait使所需的帧可用并切换到它
  • 诱导WebDriverWait使所需元素成为可点击的。
  • 您可以使用以下定位器策略

    • 代码块:

      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()
      
  • 浏览器快照:

重新验证码

于 2019-11-29T21:09:22.227 回答