0

I'm trying to write a VB script that will log into a secure website and download a series of reports.

The following gets me into the website, but after login the whole site is written in javascript.

Dim oIE
Set oIE = CreateObject("InternetExplorer.Application")
With oIE
    .Visible = True
    .Navigate SecureWebsite
    Do While .Busy Or Not .readyState = 4: WScript.Sleep 100: Loop
    Do Until .document.readyState = "complete": WScript.Sleep 100: Loop
    Do While TypeName(.document.getElementById("username")) = "Null": WScript.Sleep 100: Loop
End With

Set Helem = oIE.document.getElementByID("username")
Helem.Value = "myusername" 
Set Helem = oIE.document.getElementByID("password")
Helem.Value = "mypassword" 

Call oIE.Document.all.loginForm.submit

I've found a link that I can use with parameters to search for the reports I need. When I follow the link, Internet Explorer returns a JSON file that I can open/download. The JSON file contains a Report ID that I can use as a parameter in another link to download the file that I need.

Is there any way using the InternetExplorer object to read the text contents of the JSON file into a variable so that I can parse the Report ID out of it? All the examples I've found use the MSXML2.XMLHTTP object, but that disconnects it from the sign-on I've achieved in the InternetExplorer object.

ImagineMBE
  • 440
  • 3
  • 7
  • 1
    Does this answer your question? [How to download and get values from JSON file using VBScript or batch file?](https://stackoverflow.com/questions/51431965/how-to-download-and-get-values-from-json-file-using-vbscript-or-batch-file) – user692942 Mar 16 '20 at 16:59
  • Thanks, but that uses the MSXML2.XMLHTTP object, which has no connection to the authentication I achieved in the InternetExplorer.Application object. – ImagineMBE Mar 16 '20 at 21:27

1 Answers1

0

I ended up doing this in C#. The website had redirects and SSO so I couldn't get a direct WebClient Get/Post, but I compromised by logging in using a WebBrowser object and then passing the cookies to a HttpWebRequest object, per this excellent guide:

https://www.codeproject.com/Tips/659004/Download-of-file-with-open-save-dialog-box

ImagineMBE
  • 440
  • 3
  • 7