iTunes connect VBA 的自动化



我正在尝试通过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 = "username@outlook.com"
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

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

我会使用 vba 的硒基本包装器并切换到 iframe。当我有时间时,我会尝试改进这一点,但现在这有效。

安装硒后,您需要通过VBE > Tools > References添加引用以Selenium 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 "Joe.Bloggs@aol.com"
.FindElementByCss("#sign-in").Click
'Other code....
Stop                                     '<=Delete me later
.Quit
End With
End Sub

最新更新