The VBScript Network and Systems Administrator's Cafe

Oct 3 2008   3:00PM GMT

How to retrieve HTML web pages with VBScript via the Microsoft.XmlHttp object

Jerry Lees Jerry Lees Profile: Jerry Lees

Recently, I had a situation where I had to pull down a HTML page to compare it to a known copy of the page. Certainly, IE or FireFox– or Google’s Chrome would have done the trick and I could have viewed the source. But that would require me to do work every time we needed to check the page against the known good source.

 Instead I wrote a script to pull the HTML source and echo the response to the console (or a messag box if you are not using cscript to execute the script). While not a full blown HTTP QA script it does do the job of getting the HTTP responses from the server and is certainly a core part of any QA script anyone would write.

Basically the script uses the Microsoft.XMLHTTP object to preform all the HTTP calls and retrieve the HTML page. It sounds scary, but if you look at the script below I think you’ll find that it really is quite easy to accomplish.  So, here is the script’s code:

URL=”http://www.gamersigs.net/
Set WshShell = WScript.CreateObject(“WScript.Shell”)
Set http = CreateObject(“Microsoft.XmlHttp”)

On Error Resume Next
http.open “GET”, URL, False
http.send “”
if err.Number = 0 Then
     WScript.Echo http.responseText
Else
     Wscript.Echo “error ” & Err.Number & “: ” & Err.Description
End If
set WshShell = Nothing
Set http = Nothing

Enjoy!

3  Comments on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • curiousity
    what is the function of the WScript.Shell object in this script?
    10 pointsBadges:
    report
  • Rickcable
    Thanks for sharing. I'm adding an email component to this then making it a scheduled task. Thus creating my own up-time service.


    20 pointsBadges:
    report
  • Rickcable
    For "Curiosity's" previous post.  The WScript.Shell give your code a virtual command line environment in which to run. This is NOT creating a Wscript object, rather it is creating a window's shell object.
    20 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: