无法在 AWS 中使用 VBA 登录网站



我是一个能力非常有限的业余爱好者,运行一些VBA代码来抓取对我很重要的网站。我希望该程序能够从我的笔记本电脑 24/7 全天候可靠运行,这不是因为家庭 WiFi 丢失、Microsoft更新等,所以我正在尝试使用运行 Excel 10 的 Windows 2016 虚拟机从 AWS 运行该程序。 下面的一段 VBA 代码在我的笔记本电脑上运行良好,将我登录到我的网站,但在 AWS 虚拟机上运行时会失败。 首先,在 AWS 中使用 Internet Explorer 作为我的浏览器时,从键盘和 VBA 中,该网站的登录页面不会显示电子邮件地址和密码的输入框,直到我将其设置为受信任的站点。(Firefox 没有任何问题,但我在我的 VBA 程序中坚持使用互联网浏览器(。此时,整个网站都可以通过键盘正常工作。但是,从VBA中,当我使网站可见时,我可以看到电子邮件地址和密码未输入到其输入框中,因此我无法进入网站。 谁能告诉我我需要做什么才能允许我在 AWS 虚拟机上从 VBA 登录此网站?

MyURL = "https://app.harmoney.com/accounts/sign_in"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.navigate MyURL
MyBrowser.Visible = False
Do: Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.account_email.Value = "My email address in here"
HTMLDoc.all.account_password.Value = "My password in here"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next

这里是相同的代码,但它使用后期绑定

请试一试

Sub harmoney()
MyURL = "https://app.harmoney.com/accounts/sign_in"
'   Dim myBrowser As InternetExplorer                ' early binding
'   Set myBrowser = New InternetExplorer             ' requires reference to Microsoft Internet Controls
Const READYSTATE_COMPLETE = 4
Dim myBrowser As Object                          ' late binding
Set myBrowser = CreateObject("InternetExplorer.Application")
myBrowser.Silent = False
myBrowser.Visible = True
myBrowser.navigate MyURL
Do: Loop Until myBrowser.readyState = READYSTATE_COMPLETE   ' 4
Set HTMLDoc = myBrowser.document
HTMLDoc.all.account_email.Value = "My email address in here"
HTMLDoc.all.account_password.Value = "My password in here"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
End Sub

最新更新