gpt4 book ai didi

python-3.x - 在 Python Selenium 中处理 reCAPTCHA

转载 作者:行者123 更新时间:2023-12-03 08:50:15 25 4
gpt4 key购买 nike

我需要使用 python selenium 自动化网页,但它遇到了 reCaptcha,它位于另一个框架中。我想解决验证码问题,并在解决验证码问题后单击登录按钮继续执行脚本;然而,这会变得很棘手,因为涉及到一个框架,并且该框架需要切换回默认内容。有人可以在这方面帮助我吗?

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import time
browser = webdriver.Chrome()
browser.delete_all_cookies()
browser.maximize_window()
browser.get("https://developer.syntecx.org/ptcl_ebills/signin.php")
browser.switch_to.frame(browser.find_element_by_tag_name("iframe"))
browser.find_element_by_xpath("//*[@id='recaptcha-anchor']/div[1]").click()
time.sleep(20)
browser.switch_to_default_content()
browser.find_element_by_xpath("//*[@id='login']/button").click()

最佳答案

填写电子邮件密码字段后,单击 您可以使用以下Locator Strategies :

  • 代码块:

    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:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://developer.syntecx.org/ptcl_ebills/signin.php")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#email"))).send_keys("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b5a687a7f444e77777a735b686f7a7870746d7e697d77746c35787476" rel="noreferrer noopener nofollow">[email protected]</a>")
    driver.find_element_by_css_selector("input#password").send_keys("Asad_Ullah")
    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-checkbox.goog-inline-block.recaptcha-checkbox-unchecked.rc-anchor-checkbox"))).click()
    driver.switch_to_default_content()
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-primary.block.full-width.m-b"))).click()
  • 浏览器快照:

reCAPTCHA

关于python-3.x - 在 Python Selenium 中处理 reCAPTCHA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59403852/

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