使用 selenium 和 python 的 anticaptcha 令牌绕过 recaptcha v2

问题描述 投票:0回答:0

大家!

我正在尝试创建一个自动化脚本,但我卡在了网站的第一页。我试图绕过登录页面上的 google recaptcha v2,但我无法提交从 Anti-Captcha 获得的令牌。我已经尝试了我发现的所有可能的解决方案,但是当我单击“下一步”按钮时。它不会移动到下一页并在 recaptcha 下返回错误“请完成验证码”。

这是我的代码,注释行是我尝试过的解决方案:

网站:cacms.state.gov/s/new-appointment

driver.get('https://cacms.state.gov/s/new-appointment')

dropdown = WebDriverWait(driver, 30).until(
            EC.presence_of_element_located((By.XPATH, '//*[@id="select-45"]')))
select_object = Select(dropdown)

# Select the desired option by its value
select_object.select_by_value("GetCountryListPortal.m0N3d00000002vbEAA")

# Locate the reCAPTCHA iframe using the provided XPath
iframe_element = WebDriverWait(driver, 15).until(
    EC.presence_of_element_located((By.XPATH, '/html/body/div[3]/div[3]/div/div/div/div/div[3]/div/div/div/article/div/flowruntime-flow/flowruntime-lwc-body/div/flowruntime-list-container/div/flowruntime-base-section/div/flowruntime-screen-field[5]/flowruntime-list-container/div/flowruntime-base-section/div/flowruntime-screen-field/flowruntime-list-container/div/flowruntime-base-section/div/flowruntime-screen-field[2]/flowruntime-aura-field/div/iframe')))
driver.switch_to.frame(iframe_element)

api_key = 'my api key here'
site_key = '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI'

# Solve the reCAPTCHA using the Anti-captcha service
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask('https://cacms.state.gov/s/new-appointment', site_key, is_invisible=True)
job = client.createTask(task)
job.join()
solution = job.get_solution_response()


print("Solution: " + str(solution))
driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "{}";'.format(solution))
print("Callback Function triggered.")

time.sleep(10)

# Switch back to the main content
driver.switch_to.default_content()


# Click the "next" button
next_btn = WebDriverWait(driver, 15).until(
            EC.presence_of_element_located((By.XPATH, '/html/body/div[3]/div[3]/div/div/div/div/div[3]/div/div/div/article/div/flowruntime-flow/flowruntime-navigation-bar/footer/div[2]/lightning-button/button')))
next_btn.click()

time.sleep(60)

有人可以帮我解决这个问题吗?

我正在使用 selenium 和 python 创建一个自动化脚本。我试图使用反验证码服务绕过 google recaptcha v2 但我无法提交解决方案(注入令牌),我已经尝试了所有方法,包括回调函数方法。我希望它在注入令牌后进入下一页。

python google-chrome selenium-webdriver selenium-chromedriver recaptcha
© www.soinside.com 2019 - 2024. All rights reserved.