1

Using the following code in my vbscript

Dim o
Set o = CreateObject("MSXML2.XMLHTTP")
o.open "GET", "http://somesight.com/blah?234", False
o.send

Wscript.Echo o.responseText

I am trying to write out data from and external site. But most the data i want is created from a javascript function with in, and is not accessible this way, because when i run this script it says:

You must have JavaScript enabled.

Is there a way to simulate having Javascript in a vbscript, or perhaps translating the o.responseText with javascript enabled?

Thanks so much in advance

3
  • Did you mean to get the source code of any web page ? Commented Aug 7, 2014 at 23:02
  • @Hackoo: basically, but after the javascript functions that were on the page have ran. The javascript calls retrieves the data from the server and displays it. That displayed data is what I am trying to get. Does that make any since? Commented Aug 7, 2014 at 23:27
  • I can get the data if I have a browser. Maybe i need to approach the problem differently, but I like to grab this data and put it in a data sheet. Also there are different values i can put in, so I need a programmatic solution it seems. Commented Aug 7, 2014 at 23:32

1 Answer 1

1

Try this code :

Option Explicit
Const TriStateTrue = -1 ' Pour la prise en charge de l'Unicode
Dim URL,ie,Titre,objFSO,ws,strFileHTML,strFileTxt,strFileHTMLAscii
Dim objHTMLFile,objTxtFile,strFileTxtAscii,DataHTML,DataTxt
URL = InputBox("Entrez l'URL pour y extraire son Code Source HTML "&vbcr&vbcr&_
"Exemple ""http://www.google.fr""","Extraction du Code Source © Hackoo © 2014",_
"http://stackoverflow.com/questions/25193018/getting-web-content-that-has-javascript-using-vbscript")
If URL = "" Then WScript.Quit
Titre = "Extraction du Code Source de " & URL
Set ie = CreateObject("InternetExplorer.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileHTML = "CodeSourceHTML.txt"
strFileTxt = "CodeSourceTxt.txt"
strFileHTMLAscii = "SourceCodeHTML.txt"
strFileTxtAscii = "SourceCodeTxt.txt"
ie.Navigate(URL)
ie.Visible=false
DO WHILE ie.busy
    wscript.sleep 100
LOOP
'***********************To Get Data in HTML mode****************************
DataHTML = ie.document.documentElement.innerHTML
DataTxt = ie.document.documentElement.innerText
Set objHTMLFile = objFSO.OpenTextFile(strFileHTML, 2, True, TriStateTrue)
objHTMLFile.WriteLine(Titre&vbcr&String(120,"*"))
objHTMLFile.WriteLine(DataHTML)
objHTMLFile.Close
'************************To Get Data in Texte mode**************************
Set objTxtFile = objFSO.OpenTextFile(strFileTxt, 2, True, TriStateTrue)
objTxtFile.WriteLine(Titre&vbcr&String(120,"*"))
objTxtFile.WriteLine(DataTxt)
objTxtFile.Close
ie.Quit
Set ie=Nothing
Call Convert(strFileTxt,strFileTxtAscii)
objfso.DeleteFile strFileTxt
Call Ouvrir(strFileTxtAscii)
Call Convert(strFileHTML,strFileHTMLAscii)
objfso.DeleteFile strFileHTML
Call Ouvrir(strFileHTMLAscii)
wscript.Quit
'*************************************************************************
Function Ouvrir(File)
    Dim ws
    Set ws=CreateObject("wscript.shell")
    ws.run "Notepad.exe "& File,1,True
end Function
'*************************************************************************
Sub Convert(UnicodeFile,AsciiFile)
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const ModeAscii = 0, ModeUnicode = -1
    Dim fso, f_in, f_out
    Set fso = CreateObject("Scripting.FileSystemObject" )
    Set f_in = fso.OpenTextFile(UnicodeFile, ForReading,, ModeUnicode)
    Set f_out = fso.OpenTextFile(AsciiFile, ForWriting, true, ModeAscii)
    Do Until f_in.AtEndOfStream
        f_out.Write f_in.Read(1)
    Loop
    f_in.Close
    f_out.Close
End Sub
'*************************************************************************
Sign up to request clarification or add additional context in comments.

4 Comments

That looks promising. I will try it this evening, and let you know. Thanks
I tried the above script as is, and it comes close to what i want, but for some reason, the data from the javascript function within the code is not being called. Perhaps there needs to be a pause or wait for any functions on page to finish?
Actually with: DO WHILE ie.busy wscript.sleep 100 LOOP it should be waiting long enough.. i wonder why the functions aren't bringing back data.
Right now im looking into Snoopy and GreaseMonkey to see if either works. You have any experience with these?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.