首页 > 解决方案 > Google reCAPTCHA v2 和 Selenium

问题描述

有没有办法从 CAPTCHA 中选择图像并稍后使用 python selenium 单击它们?这是我当前的代码:

import time

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
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(ChromeDriverManager().install(), options=options)
driver.get("https://patrickhlauke.github.io/recaptcha/")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name^='a-'][src^='https://www.google.com/recaptcha/api2/anchor?']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[@id='recaptcha-anchor']"))).click()
#WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[2]/div[3]/div[1]/div/div/span[@id='rc-imageselect-target']"))).click()

frames = driver.find_elements_by_tag_name("iframe")
frames[0].find_element_by_xpath('//*[@id="rc-imageselect-target"]/table/tbody/tr[2]/td[3]/div/div[1]/img')

标签: pythonseleniumselenium-webdriverautomationcaptcha

解决方案


推荐阅读