|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
liucqa 发表于 2012-1-18 15:17
按F12快捷键调出IE开发者工具栏 >>> Script(脚本)选项卡 >>> 复制如下图代码到内容文本框中 >>> 点击 Ru ...
依据我的思路也写了个简易的,没有管证书加载那块,只写了登录的。
- Dim FLAG As Boolean
- Dim i&
- Private Sub LoginCbn_Click()
- Dim T As Single, T1 As Single
- If FLAG = True Then
- With WebBrowser1.Document.frames(0).Document
- .all("loginUser.user_name").Value = userTbx.Value
- .all("user.password").Value = PsdTbx.Value
- .all("randCode").Value = RndcodeTbx.Value
- T1 = Timer
- Do Until Timer > T1 + 30
- On Error GoTo ERRT
- .all("subLink").Click
- T = Timer
- Do Until Timer > T + 2
- DoEvents
- Loop
- Loop
- End With
- End If
- ERRT:
- If ERR.Number = 70 Then MsgBox "请更换验证码或已经登录成功了!": Exit Sub
- End Sub
- Private Sub UserForm_Activate()
- Dim T As Single
- With WebBrowser1
- .Silent = True
- .Navigate "https://dynamic.12306.cn/otsweb/main.jsp"
- Do Until .ReadyState = READYSTATE_COMPLETE
- DoEvents
- Loop
- T = Timer
- On Error Resume Next
- Do Until InStr(.Document.frames(0).Document.BODY.innertext, "忘记用户名/密码?") > 0 Or Timer > T + 8
- DoEvents
- Loop
- On Error GoTo 0
- If Timer < T + 8 Then
- MsgBox "网页加载完毕!"
- FLAG = True
- Else
- MsgBox "登陆超时!"
- FLAG = False
- End If
- End With
- End Sub
- Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
- If URL Like "*method=*" Then
- i = i + 1
- Label4.Caption = "提交第" & i - 1 & "次" & vbCrLf & URL
- pDisp.Document.parentWindow.execScript "window.alert=null;"
- End If
- End Sub
复制代码
|
|