奇葩的表单,用VBS无法稳定自动批量提交
表单代码部分内容如下:
<label class="pwd" for="lgPwd">密码</label>
<input name="password" id="lgPwd" type="password" maxLength="32" />
<label id="pwdTipStr" for="lgPwd">请输入密码</label>
<input class="subBtn" id="loginSub" type="button" value="确 定" />
我写的VBS代码是这样子的:
On Error Resume Next'出现错误程序继续运行
dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
dim iurl,ipassword,ipasswordId,iEnterId,PasswordFielName
iurl = "http://xxx.xxx.xxx"
ipasswordId = "lgPwd"
iEnterId = "loginSub"
PasswordFielName = "密码文件.txt"
sub CreaterWeb(s_url,username,usernameId,password,passwordId,EnterId)'网页自动登录
On Error Resume Next'出现错误程序继续运行
dim IE
Set IE =CreateObject("InternetExplorer.Application")'调用IE程序
IE.FullScreen=0'全屏化IE对象
IE.Visible = True'窗口可视化,若为false,则不显示浏览器
IE.Navigate s_url'打开网站
Do while IE.ReadyState<> 4 or IE.busy'用循环语句确保网页加载完毕才执行下面操作
wscript.sleep 2000'设置延迟2000ms
loop
'IE.document.getelementByid(usernameId).click'模拟第一次用户名按键的点击
'IE.document.getelementByid(usernameId).value=username'修改(传入)账户
IE.document.getelementByid(passwordId).click'模拟第2次密码按键的点击
Do while IE.ReadyState<> 4 or IE.busy'用循环语句确保网页加载完毕才执行下面操作
wscript.sleep 2000'设置延迟2000ms
loop
IE.document.getelementByid(passwordId).value=password'修改(传入)密码
Do while IE.ReadyState<> 4 or IE.busy'用循环语句确保网页加载完毕才执行下面操作
wscript.sleep 4000'设置延迟4000ms
loop
'IE.document.getelementByid(EnterId).click'模拟第3次登陆按键的点击
'Do while IE.ReadyState<> 4 or IE.busy'用循环语句确保网页加载完毕才执行下面操作
' wscript.sleep 4000'设置延迟4000ms
'loop
'IE.document.getelementById("guestWifiPwd").value=password'名字找元素
end sub
sub ForFilePasswordCreaterWeb(FielName,Sum)
dim File2,str2,str2len
Set File2=objFSO.OpenTextFile(FielName,1)
Do Until File2.AtEndOfStream
ipassword = File2.ReadLine
str2len = len(ipassword)
if (5 < str2len) and (33 > str2len) then
CreaterWeb iurl,"","",ipassword,ipasswordId,iEnterId
'wscript.sleep 10000'设置延迟10000ms
Sum = Sum - 1
if 1 > Sum then
exit do
end if
end if
loop
File2.close
end sub
ForFilePasswordCreaterWeb PasswordFielName ,19
msgbox "19次完毕"
密码文件.txt 里有多行密码。但是运行后,IE打开了19个相同网页页面,有一部分页面确实递交了密码,但是很多页面的密码框就无法输入指定的密码,密码框空白的,也没有自动提交,请教各位高手,正确的代码应该怎么写呢?谢谢