0

I have tried two VBA XML methods for logging on to the USGA Website, it seems straight forward, but neither works?! To test this, you will need your own GHIN Number and Last Name. Can someone please point out how I an screwing this up?

website = "https://www.ghin.com/login"

Sub Get_GHIN_Data()

Dim request As Object
Dim response As String
Dim html As New HTMLDocument
Dim website As String
Dim price As Variant

website = "https://www.ghin.com/login"
Set request = CreateObject("MSXML2.XMLHTTP")
request.Open "GET", website, False
'request.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
request.send

response = StrConv(request.responseBody, vbUnicode)
html.body.innerHTML = response

'********* Method 1 ************************************
'Dim oLogin As Object, oPassword As Object
'Set oLogin = .document.getElementsByName("ghinNumber")(0)
'Set oPassword = .document.getElementsByName("lastName")(0)

'oLogin.Value = ghinNumber  'real GHIN NUMBER
'oPassword.Value = LastName   'real Last Name
'html.document.forms(0).submit

'********* Method 2 ************************************
'html.getElementById("ghinNumber").Value = "ghinNumber"  'real GHIN NUMBER
'html.getElementById("lastName").Value = "Last name"      'real Last Name
'html.getElementClassName("btn fill cardinal").Click
'html.forms(0).submit

End Sub
RWB
  • 107
  • 8

1 Answers1

0

Did you try this way? I think it will work.

Sub GetInformation()
    Const Url = "https://api2.ghin.com/api/v1/public/login.json?"
    Dim Http As New XMLHTTP60, ghinNum$, lastName$

    ghinNum = ""            'put your ghinNum here
    lastName = ""           'put your lastName here

    With Http
        .Open "GET", Url & "ghinNumber=" & ghinNum & "&lastName=" & lastName & "&remember_me=false", False
        .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36"
        .setRequestHeader "Referer", "https://www.ghin.com/login"
        .send
    End With

    MsgBox Http.responseText
End Sub
asmitu
  • 175
  • 11
  • WOW! Thank you. Yes, that logged me in! Thank you. Where in the world did you come up with "Const Url = "https://api2.ghin.com/api/v1/public/login.json?"" and “construct header?” (I am a pure beginner.) -RB – RWB Apr 07 '20 at 12:15
  • 1
    [This](https://stackoverflow.com/a/3019085/12965196) is how you can monitor the request in chrome. If this answer helped solve the issue you were facing, make sure to accept this as an answer. [This](https://meta.stackexchange.com/a/5235/673712) is how you can by the way. – asmitu Apr 07 '20 at 12:24
  • Ultimately, after the log-in, I am trying to land on this "GHIN IndexFollowing-Page" to pull data: "https://www.ghin.com/golfer-lookup/following". Can I add a line of code to you log in that we pull the response in from the " ..../golfer-lookup/following" internal page. I am trying to pull the up to the minute Indees from my buddies, who are listed on the "GHIN IndexFollowing-Page", so that we can assign tee grouping for our weekly game. Thanks again! RB – RWB Apr 07 '20 at 12:31
  • You have helped solve a "real world" problem. This is fantastic! RB – RWB Apr 07 '20 at 12:34
  • I tried this adjustment to get to the "following page", and it did not work. ghinNum = "1234567" lastName = "XXXXXXX" Following = "/golfer-lookup/following" With Http .Open "GET", Url & "ghinNumber=" & ghinNum & "&lastName=" & lastName & Following & "&remember_me=False", False – RWB Apr 07 '20 at 13:12
  • Better Framed Question Here: https://stackoverflow.com/questions/61082591/usga-ghin-2nd-page-information-get-the-info-from-a-2nd-web-page-after-an-xml – RWB Apr 07 '20 at 15:47