{"id":70383,"date":"2005-02-22T16:15:00","date_gmt":"2005-02-22T16:15:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/02\/22\/how-can-i-tell-whether-a-web-page-is-accessible\/"},"modified":"2005-02-22T16:15:00","modified_gmt":"2005-02-22T16:15:00","slug":"how-can-i-tell-whether-a-web-page-is-accessible","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-tell-whether-a-web-page-is-accessible\/","title":{"rendered":"How Can I Tell Whether a Web Page is Accessible?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I tell whether or not a Web page is accessible?<BR><BR>&#8212; JW<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, JW. To tell you the truth, these are the kinds of questions we hate, questions where we don\u2019t know the answer off the top of our heads but where it <I>seems<\/I> 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.<\/P>\n<P>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\u2019t 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:<\/P><PRE class=\"codeSample\">On Error Resume Next<\/p>\n<p>strURL = &#8220;http:\/\/www.microsoft.com\/technet\/scriptcenter\/default.mspx&#8221;<\/p>\n<p>Set objHTTP = CreateObject(&#8220;MSXML2.XMLHTTP&#8221;) \nobjHTTP.Open &#8220;GET&#8221;, strURL, FALSE\nobjHTTP.Send<\/p>\n<p>Wscript.Echo(objHTTP.statusText)\n<\/PRE>\n<P>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 <B>Open<\/B> method, passing three parameters: \u201cGET\u201d (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 <B>Send<\/B> method to send our request to the HTTP server.<\/P>\n<P>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 <B>statusText<\/B> property. If statusText is <B>OK<\/B> then the page was accessible; if it\u2019s anything other than OK, then something went wrong and we couldn\u2019t reach the specified URL. <\/P>\n<P>Incidentally, the contents of the Web page are returned as the <B>ResponseText<\/B> 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:<\/P><PRE class=\"codeSample\">On Error Resume Next<\/p>\n<p>Const ForWriting = 2<\/p>\n<p>strURL=&#8221;http:\/\/www.microsoft.com\/technet\/scriptcenter\/default.mspx&#8221;<\/p>\n<p>Set objHTTP = CreateObject(&#8220;MSXML2.XMLHTTP&#8221;) \nobjHTTP.Open &#8220;GET&#8221;, strURL, FALSE\nobjHTTP.Send<\/p>\n<p>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)\nSet objFile = objFSO.CreateTextFile(&#8220;script_center.htm&#8221;, ForWriting)\nobjFile.Write objHTTP.ResponseText\nobjFile.Close\n<\/PRE>\n<P>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.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I tell whether or not a Web page is accessible?&#8212; JW Hey, JW. To tell you the truth, these are the kinds of questions we hate, questions where we don\u2019t know the answer off the top of our heads but where it seems like there ought to be a way [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[40,3,4,5,30],"class_list":["post-70383","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-filesystemobject","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-web-pages-and-htas"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I tell whether or not a Web page is accessible?&#8212; JW Hey, JW. To tell you the truth, these are the kinds of questions we hate, questions where we don\u2019t know the answer off the top of our heads but where it seems like there ought to be a way [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=70383"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70383\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=70383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}