通过vba登录网站失败:超时过期错误消息

时间:2019-04-15 16:46:33

标签: excel vba login timeout

我是Web编程的完整入门者,我想通过vba excel从我的银行站点下载文件。该代码可以正确填写并单击登录按钮,但该网站由于“超时已过期”而拒绝登录。 我怎么解决这个问题?

缺少cookie,如何提供?

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

1 个答案:

答案 0 :(得分:0)

您可以尝试

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