使用 VBA 登录到安全的 https 网站 [英] Log in to secured https website with VBA

查看:80
本文介绍了使用 VBA 登录到安全的 https 网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 VBA 脚本自动登录我的银行帐户并从网站返回一些数据来自动化我的日常任务.但是,我无法编写可以登录该网站的宏 -

以下 google.com 代码:​​

Sub LoginHttps()Dim IE 作为对象Set IE = CreateObject("InternetExplorer.Application")用 IE.Top = 0.左 = 0. 高度 = 1000.宽度 = 1250.可见 = 真.导航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"结束于结束子

以及生成 424 错误的银行网站代码:

Sub LoginHttps()Dim IE 作为对象Set IE = CreateObject("InternetExplorer.Application")用 IE.Top = 0.左 = 0. 高度 = 1000.宽度 = 1250.可见 = 真.导航https://online.mbank.pl/pl/Login"Do While .Busy or Not .ReadyState = 4: DoEvents: Loop.Document.getElementById("userID").Value = "input"结束于结束子

我想知道是否有任何方法可以通过 VBA 访问这些输入框,或者由银行程序员保护.

解决方案

这里是三个顺序检查:第一个 Do ... Loop 是通常的 IE 状态检查,第二个 - 文档完整性检查,以及第三 - 目标元素检查,当目标节点未准备好时,它为我返回 Null (而不是 HTMLInputElement 对象,当它准备好时).

Sub LoginHttps()Dim IE 作为对象Set IE = CreateObject("InternetExplorer.Application")用 IE.Top = 0.左 = 0. 高度 = 1000.宽度 = 1250.可见 = 真.导航https://online.mbank.pl/pl/Login"做 While .Busy 或 .ReadyState <4:DoEvents:循环直到 .document.readyState = "complete": DoEvents: LoopDo While IsNull(.document.getElementById("userID")): DoEvents: Loop.document.getElementById("userID").Value = "input"结束于结束子

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

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.

解决方案

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

这篇关于使用 VBA 登录到安全的 https 网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆