Thanks! I'll give it a try later today and let you know.
Script to grab web page
Collapse
X
-
-
One thing I forgot to mention is that script isn't conditional...i t will print the response, no matter what the response was. You might want to implement some if-then-else logic.
Also, you might want to add this line after line 6:
If you do decide to do it conditionally, you might be interested in this article, which shows all the members and methods of the MSXML2.ServerXM LHTTP object.Code:xmlhttp.waitForResponse()
Comment
-
Here, slightly more refined:
It's a bit longer because I've included comments.Code:'define vars url = "http://bytes.com" path = "C:\dev\vbs\temp.txt" 'instantiate Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP") Set fso = CreateObject("Scripting.FileSystemObject") Set txtfile = fso.OpenTextFile(path, 2, True) Set oWS = WScript.CreateObject("WScript.Shell") 'make request xmlhttp.open "GET", url, false xmlhttp.send "" 'wait for response xmlhttp.waitForResponse() 'if status is 200, then it's OK if xmlhttp.status = 200 then txtfile.WriteLine(xmlhttp.responseText) txtfile.Close 'enable this to print 'oWS.Run "NotePad.exe /p " + path 'enable this to just display oWS.Run "notepad.exe " + path else 'popup bad response, or just omit to end WScript.Echo("bad response") end if 'destroy objects. I'm not sure this is necessary Set txtfile = nothing Set xmlhttp = nothing Set oWS = nothing Set fso = nothing
Now, the program will check that the HTTP status is 200 before proceeding. Right now it will let you know it failed, but if you remove lines 22-24, you will get rid of the popup.
If you want it to print, uncomment 19 and comment 21.
Hope this helps.Comment
-
-
Success! That's just alright, man. I need to put this on my wife's desktop with the printer to test that part out but Notepad opens the file automatically as is.
The only thing I need to add would be a timer to make it fetch every minute or two. It would be nice if it could print a rendered html page but that can wait.
I'll look later but if you know where the docs are for the timer, I can look it up. Also, if you already know what I should look into for rendering the html for the printer, that would be just great. For now, plain text will be good enough.
Saved me some grief. Thanks again!Comment
-
Comment