selenium识别验证码是否通过

本文最后更新于:2022年10月4日 晚上

其实就是识别验证码勾选框有没有打勾。

原理

切换到验证码的iframe页anchor,获取元素recaptcha-anchor的属性aria-checked就可以了。falsetrue

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import time
import requests
from selenium import webdriver

options = webdriver.ChromeOptions()
driver = webdriver.Chrome('selenium/chromedriver.exe', options=options)

driver.get("https://www.google.com/recaptcha/api2/demo")

# 切换到勾选框
iframe = driver.find_element_by_css_selector('iframe[src*="anchor"]')
driver.switch_to.frame(iframe)

# 获取勾选框的打勾状态
for i in range(30):
anchor = driver.find_element_by_id('recaptcha-anchor')
is_checked = anchor.get_attribute("aria-checked")
print('当前识别状态:', is_checked)
time.sleep(3)

selenium识别验证码是否通过
https://pawswrite.xyz/posts/21451.html
作者
Rainbow
发布于
2022年8月12日
许可协议