html - 通过 Excel VBA 使用 JS 登录网站

标签 html excel vba internet-explorer web-scraping

我有一个宏,可以让我按一下按钮就可以登录网站。然而,事实并非如此。 有人已经试图帮助我,但正如他自己所说,这有点超出了他的理解范围。所以在这里我再次尝试更多细节!

这是他发给我的最后一个代码。

Public Sub GetInfo()
    Dim IE As New InternetExplorer
    With IE
        .Visible = True
        .navigate "https://apiweb.biomerieux.com/login"
        While .Busy Or .readyState < 4: DoEvents: Wend
        With .document.getElementById("signupEmail")
            .Focus
            .Value = "xxxx"
        End With
        Application.Wait Now + TimeSerial(0, 0, 1)
        With .document.getElementById("signupPassword")
            .Focus
            .Value = "yyyy"
        End With
        On Error Resume Next
        With .document.getElementById("signupSubmit")
            .Focus
            .Click
        End With
        '.Quit
    End With
End Sub

最奇怪的是,当您通过宏将凭据输入文本框并单击按钮时,该站点认为未输入凭据,即使已输入凭据也是如此。

我以前的助手认为可能网站上的部分 javascript 以某种方式搞砸了。

最佳答案

我认为这种更简单的方法足以完成工作。您需要做的就是让脚本等待第一个输入的 html 元素可用。

Sub LogMeIn()
    Dim IE As New InternetExplorer, post As Object, HTML As HTMLDocument

    With IE
        .Visible = True
        .navigate "https://apiweb.biomerieux.com/login"
        While .Busy Or .readyState <> 4: DoEvents: Wend
        Set HTML = .document

        With HTML
            Do: Set post = .querySelector("#signupEmail"): DoEvents: Loop While post Is Nothing
            .querySelector("#signupEmail").innerText = "imc@yahoo.com"
            .querySelector("#signupPassword").innerText = "abc12345"
            .querySelector("a > #signupSubmit").Click
        End With
    End With
End Sub

关于html - 通过 Excel VBA 使用 JS 登录网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57112160/

相关文章:

html - 尝试在 table 上做圆 Angular

Excel 2013 : Label deconfliction in labeled scatter plot

mysql - Excel Mac 2016,在 VBA 函数内调用时 ListObject 不起作用

excel - 如何处理: Run-time error '53' File not found错误

Excel VBA : Protect/Unprotect macro breaks during saves due to not ready

c# - 将 JavaScript 菜单放入 Asp.Net 页面时出现问题

html - CSS IE 悬停状态问题

javascript - Style.backgroundColor 或 style.background 没有执行它的功能

excel - 语言服务提交: Error '91'

vba - 打开工作簿时自动运行宏?