简体   繁体   中英

Fail to log into websites using VBA in AWS

I am an amateur of very limited capabilities running some VBA code to scrape a website of importance to me. I want the program to run reliably from my laptop 24/7, which it doesn't because of home WiFi dropouts, Microsoft updates etc, so I am trying to run the program instead from AWS using a Windows 10 virtual machine running Excel 2016. The piece of VBA code below works well on my laptop logging me into my website, but when running on the AWS virtual machine it fails. Firstly, in AWS using internet Explorer for my browser, from both the keyboard and VBA the sign-in page of this website did not display input boxes for an email address and password, until I made it a trusted site. (Had no problems at all from Firefox but I'm stuck with internet Explorer from within my VBA program). At that point, the whole website worked correctly from the keyboard. However, from VBA, when I make the website visible, I can see that the email address and password are not being entered into their input boxes, so consequently I cannot get into the website. Can anybody tell me what I need to do to allow me to log into this website from VBA on the AWS virtual machine?

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

here is the same code, but it uses late binding

please give it a go

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM