Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
873 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...