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!

 Comment 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: