python - 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')
解决方案
推荐阅读
- python - 将字典拟合到正态分布曲线
- java - HTTP 状态 404 - /WEB-INF/jsp/welcome.html
- ios - 为什么我的 xib 文件没有正确显示?
- c# - 图像未显示(Xamarin 表单)
- sql - SQL 从列中获取第一个值并将其复制到新列中
- sql - BigQuery - 组合零散的事件
- java-native-interface - 如何在 jni(java 到 c++)以及(c++ 到 java)中传递和返回属性数组
- sql-server - 在 SQL Server 中显示选定的日期范围
- python - 打印工作,但使用回溯解决数独时返回值为 None
- android - Proguard:ArrayAdapter.createViewFromResource 中的 NullPointerException,堆栈跟踪中没有我的任何类