/
Selenium加载人机助手进行识别并获取检查识别状态

Selenium加载人机助手进行识别并获取检查识别状态

人机助手下载地址:

 

很多用户不知道其他软件(比如selenium)如何配置人机助手进行识别,并且获取识别状态,其实原理很简单,切换到验证码的iframe页anchor,获取元素recaptcha-anchor的属性aria-checked就可以了。

代码:

import time import requests from selenium import webdriver options = webdriver.ChromeOptions() # 加载验证码插件,这里是以zip格式的文件进行加载 options.add_extension('selenium/yescap_v2.0.beta.zip') 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)

输出

当前识别状态: false 当前识别状态: false 当前识别状态: false 当前识别状态: false 当前识别状态: true 当前识别状态: true 当前识别状态: true

下载

 

如果使用普通的selenium会被检测,可以使用 undetected_chromedriver 这个库避免被检测

 

import time import requests import undetected_chromedriver as uc options = uc.ChromeOptions() # 加载验证码插件,这里是以目录的形式加载,注意区别 options.add_argument('--load-extension=D:\test\yescap_v2.0.beta') driver = uc.Chrome(options=options, use_subprocess=True, version_main=103) driver.get("https://www.google.com/recaptcha/api2/demo") # ……

 

进阶玩法
识别完成后,网页上会有识别完成的token,这个token就可以拿去用做协议提交。

具体操作:

切换到主空间,再切换到bframe框架页,获取ID为recaptcha-token的value就是token了。

Related content

如何查找 reCaptcha 系列的回调函数
如何查找 reCaptcha 系列的回调函数
More like this
如何找到 reCaptcha 需要的各项参数
如何找到 reCaptcha 需要的各项参数
More like this
FunCaptchaClassification: Funcaptcha 图像识别
FunCaptchaClassification: Funcaptcha 图像识别
Read with this
Loading Yescaptcha Human Assistant Plugin in Selenium to recognize and check the recognition status
Loading Yescaptcha Human Assistant Plugin in Selenium to recognize and check the recognition status
More like this
YesCaptcha API 开发文档
YesCaptcha API 开发文档
Read with this
Python DEMO:selenium模拟提交 demo_selenium.py
Python DEMO:selenium模拟提交 demo_selenium.py
More like this