0

I'm using VBscript to use IE to open a webpage - login - and save some data to a file.

Why use IE? - I can use VBScript to interact with the webpage - The webpage uses ajax to do verification and signing in, so simply using MSXML2.XMLHTTP wont work.

After IE log into the site, I direct it to the page I want to save as a file, the problem is this page is returning JSON data (filename.json) - so IE is prompting to open/save/saveas rather than just opening the page, so I cant save the data of the page.

The code is below. Any help is much appreciated.

Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://www.somesite.com"
Wait IE
With IE.Document
    .getElementByID("username").value = "myusername"
    .getElementByID("password").value = "mysecret"
    .getElementsByName("Login")(0).Click
End With
Wait IE
'# all fine here, logged in and redirected to members page

IE.Navigate  "https://www.somesite.com/api/data"
' # this link returns json data
'# this is where everything stops because Im getting a download/save as prompt in IE

EDIT: ok, I was able to get IE to display the content rather than downloading it by editing the registry to treat .json file as text files,Now the problem is the page is a json file, not a HTML file, so I cant get it's content by calling IE.Document.Body.InnerHTML like normal HTML pages.

How would I get the content of the page and assign it to a variable so I can process it?

tuan.ng
  • 21
  • 4
  • You could try [disabling that functionality in IE](http://9to5it.com/internet-explorer-disable-do-you-want-to-open-or-save-this-file-prompt/). – oracle certified professional Oct 10 '14 at 07:27
  • Thanks! funny thing is I read that page before and it didn't help, then I read it again and found the solution. However, now im stuck with another problem... – tuan.ng Oct 10 '14 at 12:14
  • 1
    If you found a solution, please post it as an answer, and accept it. Otherwise, you add your question to the pool of zombie questions that will never get a formal, accepted answer. – TheBlastOne Oct 13 '14 at 07:31
  • [How do I access XHR responseBody (for binary data) from Javascript in IE?](http://stackoverflow.com/questions/1919972/how-do-i-access-xhr-responsebody-for-binary-data-from-javascript-in-ie) – Sen Jacob Jul 07 '15 at 07:22

1 Answers1

0

oh, I just put this in my code:

Set objShell = CreateObject("WScript.Shell") objShell.RegWrite "HKEY_CLASSES_ROOT\.json\Content Type", "text/plain", "REG_SZ

That way the file is treated as a textfile within IE and it will just open in the page. Then I can use the normal objIE.Document.Body.InnerText to get the json contents. Then I pass that variable onto my function that decodes it all.

Hope this helps someone, because all the results on google I found did not help me. Only reason I posting on this old thread!

Cheers, Ross

Rosski
  • 62
  • 4