找深索写了一个,输入的交用户名提交不了,还是登录不上
[code][On Error Resume Next
' 定义摄像头列表,格式为:IP地址,用户名,密码
Dim cameras
cameras = Array("192.168.1.169,admin,12345")
' 遍历摄像头列表
For Each camera In cameras
' 分割字符串获取IP、用户名和密码
Dim cameraInfo
cameraInfo = Split(camera, ",")
Dim ip, username, password
ip = cameraInfo(0)
username = cameraInfo(1)
password = cameraInfo(2)
' 创建IE对象
Dim ie
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://" & ip
' 等待页面加载完成
Do While ie.Busy Or ie.ReadyState <> 4
WScript.Sleep 100
Loop
' 确保页面元素加载完成
On Error Resume Next ' 忽略错误,继续执行
Dim maxRetries, retryCount
maxRetries = 10
retryCount = 0
Do
WScript.Sleep 1000 ' 等待1秒
retryCount = retryCount + 1
Loop Until (Not ie.Document.getElementById("username") Is Nothing And Not ie.Document.getElementById("password") Is Nothing) Or retryCount >= maxRetries
On Error GoTo 0 ' 恢复错误处理
' 检查是否找到元素
If ie.Document.getElementById("username") Is Nothing Or ie.Document.getElementById("password") Is Nothing Then
MsgBox "无法找到登录元素,请检查页面结构或IP地址:" & ip
ie.Quit
WScript.Quit
End If
' 输入用户名和密码
ie.Document.getElementById("username").Value = username
ie.Document.getElementById("password").Value = password
' 触发输入框的change和input事件(确保AngularJS等框架检测到输入)
ie.Document.getElementById("username").FireEvent "onchange"
ie.Document.getElementById("username").FireEvent "oninput"
ie.Document.getElementById("password").FireEvent "onchange"
ie.Document.getElementById("password").FireEvent "oninput"
' 查找登录按钮
Dim loginButton
Set loginButton = Nothing
For Each btn In ie.Document.getElementsByTagName("button")
' 检查按钮内部是否包含 <em>登录</em>
If Not btn.getElementsByTagName("em").Item(0) Is Nothing Then
If btn.getElementsByTagName("em").Item(0).innerText = "登录" Then
Set loginButton = btn
Exit For
End If
End If
Next
' 检查是否找到登录按钮
If loginButton Is Nothing Then
MsgBox "无法找到登录按钮,请检查页面结构或IP地址:" & ip
ie.Quit
WScript.Quit
End If
' 点击登录按钮
loginButton.Click
' 等待登录完成
Do While ie.Busy Or ie.ReadyState <> 4
WScript.Sleep 100
Loop
' 检查是否登录成功
If InStr(ie.Document.body.innerHTML, "请输入用户名") > 0 Then
MsgBox "登录失败:请输入用户名。请检查用户名和密码是否正确。"
Else
MsgBox "登录成功!"
End If
' 关闭IE窗口
'ie.Quit
Next
MsgBox "所有摄像头登录完成!"/code] |