aardio 自动识别验证码输入

自动化表单填充与验证码识别

(应网友提议整理的实操记录)

缘起:网友提问催生的技术尝试

上周在发学习日志时有网友提议"在网页上识别验证码",于是尝试整合图像识别与网页自动化技术,完成了这套模拟登录流程。核心思路是:截图验证码→OCR识别→自动填充表单→提交并验证结果。

代码在这里

ini 复制代码
import soImage;
import web.view;
import string.html;
import string.ocrLite;
import string.ocrLite.defaultModels;

// 创建窗口并显示
var winform = win.form(text="找图代码生成器";right=800;bottom=600)
var wb = web.view(winform); 
winform.show();
//wb.fullscreen()

// 截图并保存处理
var img = soImage(); 
response = wb.go("http://127.0.0.1:5500/public/aaa.html")
thread.delay(1000)
img.captureWindow()
img.crop(1052,620,1140,675)
img.setJpegQuality(100)
img.save("./验证码.jpg")
var thumbnail = gdip.image("./验证码.jpg").getThumbnail(400,180);
thumbnail.save("./验证码1.jpg")

// 图像文字识别
var imgpath = "./验证码1.jpg"; 
var ocr = string.ocrLite();
var bit = gdip.bitmap(imgpath);
var text = ocr.detectBitmap(bit);  

// 自动填充表单并点击登录
for(i, value in table.eachIndex(text.blocks)){
    //输入用户名
    var username = wb.cdpWaitQuery("body > div > form > div.mb-4 > input")
    wb.cdp("DOM.focus",{nodeId = username.nodeId;})
    wb.cdp("Input.insertText",{text='admin'})
    //输入密码
    var password =wb.cdpWaitQuery("#password") ; 
    wb.cdp("DOM.focus",{nodeId = password.nodeId;})
    wb.cdp("Input.insertText",{text='123456'})
    //输入验证码
    var captcha = wb.cdpWaitQuery("#captchaInput");
    wb.cdp("DOM.focus",{nodeId = captcha.nodeId;}) 
    wb.cdp("Input.insertText",{text=value.text})
    //点击登录
    wb.waitEle("#loginForm > div.flex.items-center.justify-between > button","this.click()");
    thread.delay(1000)
    
    var successPage  = wb.cdpWaitQuery("#successPage"); 
    if(successPage){
        var html = wb.cdp('DOM.getOuterHTML',{nodeId = successPage.nodeId;})
        for(k,value in html){
            var save = string.save("./data.html",value)
            if(save){
                win.msgbox('保存html成功','提示')
                }    
            }        
    }else {
            win.msgbox('获取html失败')
        }    
    }
win.loopMessage();

因为个人技术问题,没有实现自动找验证码的位置的功能,只能设置验证码的位置截图进行图像识别,到时候需要自己更改位置,有大佬会的话可以改进一下☺

相关推荐
superman超哥1 天前
Serde 性能优化的终极武器
开发语言·rust·编程语言·rust serde·serde性能优化·rust开发工具
superman超哥7 天前
Serde 的零成本抽象设计:深入理解 Rust 序列化框架的哲学
开发语言·rust·开发工具·编程语言·rust序列化
superman超哥7 天前
序列化格式的灵活切换:Serde 生态的统一抽象力量
开发语言·rust·编程语言·rust serde·序列化格式·rust序列化格式
superman超哥8 天前
派生宏(Derive Macro)的工作原理:编译时元编程的艺术
开发语言·rust·开发工具·编程语言·rust派生宏·derive macro·rust元编程
superman超哥8 天前
处理复杂数据结构:Serde 在实战中的深度应用
开发语言·rust·开发工具·编程语言·rust serde·rust数据结构
superman超哥8 天前
错误处理与验证:Serde 中的类型安全与数据完整性
开发语言·rust·编程语言·rust编程·rust错误处理与验证·rust serde
superman超哥8 天前
自定义序列化逻辑:掌控数据编码的每一个细节
开发语言·rust·编程语言·rust自定义序列化·rust数据编码
superman超哥8 天前
Serialize 与 Deserialize Trait:Rust 类型系统与序列化的完美融合
开发语言·rust·开发工具·编程语言·rust序列化·rust类型·serialize
superman超哥8 天前
Actix-web 性能优化技巧:从原理到实践
开发语言·rust·编程语言·actix-web
superman超哥8 天前
Rust 与数据库连接池的集成:从理论到生产实践
开发语言·rust·编程语言·rust与数据库连接池的集成