iTunes的自动化连接VBA

问题描述 投票:0回答:1

我试图通过VBA自动化报告。我曾在VBA工作,但无法通过代码登录iTunes网站。有人告诉我它是用IFrame编写的,但我不知道。即使我无法将我的用户名放在登录页面的输入框中。

https://itunesconnect.apple.com/login

Dim HTMLdoc As HTMLDocument    
Dim MyBrowser As InternetExplorer

Sub check()

    Dim MyHTML_element As IHTMLElement
    Dim MyURL As String

    MyURL = "https://itunesconnect.apple.com/login"
    Set MyBrowser = New InternetExplorer

    MyBrowser.Silent = True
    MyBrowser.navigate MyURL
    MyBrowser.Visible = True

    Do
    Loop Until MyBrowser.readyState = READYSTATE_COMPLETE

    Set HTMLdoc = MyBrowser.document

    HTMLdoc.getElementsByID("account_name_text_field").Value = "[email protected]"
    HTMLdoc.all.Password.Value = "password"

    For Each MyHTML_element In HTMLdoc.getElementsByTagName("input")

        If MyHTML_element.Type = "sign-in" Then MyHTML_element.Click: Exit For

    Next

Err_Clear:

    If Err <> 0 Then

        Err.Clear

        Resume Next
    End If
End Sub
javascript html vba web-scraping
1个回答
0
投票

API听起来是个好主意。整个页面加载非常慢(至少对我来说)并且有一个iframe可以导航。

我会使用selenium basic wrapper获取vba并切换到iframe。当我有时间时,我会尽力改善这一点,但现在这个有效。

安装硒后,您需要通过VBE > Tools > ReferencesSelenium Type library添加引用。

Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver, t As Date, ele As Object
    Set d = New ChromeDriver
    Const URL = "https://itunesconnect.apple.com/login"
    Const WAIT_TIME_SECS As Long = 30
    t = Timer
    With d
        .Start "Chrome"
        .get URL
        Do
            DoEvents
            If Timer - t > WAIT_TIME_SECS Then Exit Do
            On Error Resume Next
            .SwitchToFrame "aid-auth-widget-iFrame"
            Set ele = .FindElementByCss("#account_name_text_field")
            On Error GoTo 0
        Loop While ele Is Nothing

        If ele Is Nothing Then Exit Sub
        ele.SendKeys "[email protected]"

        .FindElementByCss("#sign-in").Click

        'Other code....
        Stop                                     '<=Delete me later
        .Quit
    End With
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.