Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
869 views
in Technique[技术] by (71.8m points)

excel - Log in to secured https website with VBA

I am trying to automate my daily tasks by VBA script automatically login into my bank account and returning some data from the website. However, I cannot write such macro which could login in into this website - https://online.mbank.pl/pl/Login.

I wrote the following macro which works well with "normal" websites such google (based on input box IDs), but does not work with bank websites returning, the following error:

Run-time error 424: Object required

enter image description here

Below code for google.com:

Sub LoginHttps()

    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Top = 0
        .Left = 0
        .Height = 1000
        .Width = 1250
        .Visible = True
        .Navigate "https://www.google.com/?gfe_rd=cr&ei=N-TZVaPMAdCv8wf19aH4Bw&gws_rd=cr&fg=1"

        Do While .Busy Or Not .ReadyState = 4: DoEvents: Loop

        .Document.getElementById("lst-ib").Value = "input"
    End With
End Sub

and code for bank website which generates an 424 error:

Sub LoginHttps()

    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")

    With IE
        .Top = 0
        .Left = 0
        .Height = 1000
        .Width = 1250
        .Visible = True
        .Navigate "https://online.mbank.pl/pl/Login"

        Do While .Busy Or Not .ReadyState = 4: DoEvents: Loop

        .Document.getElementById("userID").Value = "input"
    End With
End Sub

I am wondering whether there is any method to access these input boxes by VBA or it is secured by bank programmers.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here are three sequential checks: first Do ... Loop is usual check of IE state, second - document completeness check, and third - target element check, which returns Null for me while target node not ready (instead of HTMLInputElement object when it does).

Sub LoginHttps()
    Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    With IE
        .Top = 0
        .Left = 0
        .Height = 1000
        .Width = 1250
        .Visible = True
        .Navigate "https://online.mbank.pl/pl/Login"
        Do While .Busy Or .ReadyState < 4: DoEvents: Loop
        Do Until .document.readyState = "complete": DoEvents: Loop
        Do While IsNull(.document.getElementById("userID")): DoEvents: Loop
        .document.getElementById("userID").Value = "input"
    End With
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...