I recently received the following question in my mailbox yesterday: Is it possible to retrieve the text of a page without physically opening it?
Yes, it’s possible to retrieve the document text without physically opening the page. It can be done though an XMLHTTP Request. XMLHTTP is short for Extensible Markup Language HyperText Transfer Protocol. “The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality, such as submitting form data or loading data from a server.”1
In the snippet below, I’ve created a simple mechanism to retrieve server response from this blog. The ‘OPEN’ method is used to assign a method (GET, POST, HEAD) of the pending request. The ‘SEND’ method sends the request (as detailed in the Open method) to the server.
Dim oXMLHTTP Set oXMLHTTP = CreateObject("Microsoft.XMLHttp") With oXMLHTTP .open "GET", "http://www.relevantcodes.com", False .send Reporter.ReportEvent micInfo, "Status", .statusText Reporter.ReportEvent micInfo, "Response", .responseText End with Set oXMLHTTP = Nothing
{ 3 comments… read them below or add one }
Ya Vishal..it’s working fine..
Dim oXMLHTTP
Set oXMLHTTP = CreateObject( “Microsoft.XMLHttp” )
With oXMLHTTP
.open “GET”, “http://www.google.co.in/”, False
.send
Stats=.statusText
msgbox Stats
End with
Set oXMLHTTP = Nothing
Hi Vishal,
Actually, there can be multiple reasons for this error. Could you please share with me the code that you executed and the browser(s) installed on your system?
In the meantime, I would recommend you to read the following discussions:
1. XMLHTTPRequest – Permission Denied Error
2. How do I read the contents of a remote web page?
3. Problem using MS XMLHTTPRequest via https
4. StackOverflow.com: VBScript, MSXML and Namespaces
Regards,
Anshoo
Hi Anshoo,
When i run the above code snippet i m getting an error ” Acess is denied ” at ‘.Send’ line cld u plz re look into it or what can i do for that?
Thanks in advance,
Vishal