我是一个完全的Web编程初学者,我想通过vba excel从我的银行网站下载一个文件。 代码填写表单并点击登录 buttin,但网站拒绝登录,因为"超时已过期"。如何解决这个问题?
是否缺少饼干,如何提供?
Sub Login() 'provokes timeout error from the server
Dim IEApp As Object
Dim ding As Object
Dim IEDoc As Object
Set IEApp = CreateObject("InternetExplorer.Application")
IEApp.Visible = True
IEApp.navigate "https://www.mybank/banking"
Do While IEApp.readyState <> 4: DoEvents: Loop
Set IEDoc = IEApp.document
On Error Resume Next
With IEApp.document
Do While IEApp.readyState <> 4: DoEvents: Loop
For Each ding In IEDoc.all 'username eintragen
If ding.Name = "j_username" Then
If Err = 0 Then
ding.Value = "myUsername"
On Error GoTo 0
Err.Clear
Exit For
Else
Err.Clear
End If
End If
Next
Do While IEApp.readyState <> 4: DoEvents: Loop
On Error Resume Next
For Each ding In IEDoc.all 'passwort eintragen
If ding.Name = "j_password" Then
If Err = 0 Then
ding.Value = "myPassword"
On Error GoTo 0
Err.Clear
Exit For
Else
Err.Clear
End If
End If
Next
Do While IEApp.readyState <> 4: DoEvents: Loop
On Error Resume Next 'button 'login'
For Each ding In IEDoc.all
If ding.Title = "login" And ding.Type = "button" Then
If Err = 0 Then
ding.Click
On Error GoTo 0
Err.Clear
Exit For
Else
Err.Clear
End If
End If
Next
End With
Set ding = Nothing
Set IEDoc = Nothing
Set IEApp = Nothing
End Sub
你能试试吗
Sub Login() 'provokes timeout error from the server
Dim IEApp As Object
Dim ding As Object
Dim IEDoc As Object
Set IEApp = CreateObject("InternetExplorer.Application")
IEApp.Visible = True
IEApp.navigate "https://www.mybank/banking"
Do While IEApp.readyState <> 4: DoEvents: Loop
Set IEDoc = IEApp.document
On Error Resume Next
With IEApp.document
Do While IEApp.readyState <> 4: DoEvents: Loop
With IEApp
.document.getelementsbyname("j_username")(0).Value = "myUsername"
.document.getelementsbyname("j_password")(0).Value = "myPassword"
End With