How to fetch URL contents into a String Variable?

Results 1 to 2 of 2

Thread: How to fetch URL contents into a String Variable?

  1. #1
    Jack Kurzweil Guest

    Default How to fetch URL contents into a String Variable?

    Is there an object/method that will fetch the contents of a given URL and put the HTML-returned content into a variable?

  2. #2
    Joel N Guest

    Default RE: How to fetch URL contents into a String Variab

    Assuming you&#039;re running MS server software and you have the MSXML parser on your machine you can read in the entire contents of another page and stash it in a variable this way using VBScript on the server:<BR>&#060;%<BR>Dim HttpReq<BR>Dim sHTMLString<BR>Set HttpReq = Server.CreateObject("MSXML2.XMLHTTP")<BR>HttpReq.o pen "GET", "", False<BR>HttpReq.send<BR>sHTMLString = HttpReq.responseText<BR>&#039;At this point sHTMLString should hold the html from the page<BR>&#039;you requested in the "open" line above<BR>Response.Write sHTMLString<BR>Set HttpReq = Nothing<BR>%&#062;<BR><BR>To do it from the client side do something like this in JavaScript:<BR><BR>&#060;html&#062;<BR>&#060;scrip t&#062;<BR>function getPage()<BR>{<BR>var False;<BR>var HttpReq;<BR>var sHTMLString;<BR>False = 0;<BR>HttpReq = new ActiveXObject("MSXML2.XMLHTTP");<BR>" GET", "", False);<BR>HttpReq.send();<BR>sHTMLString = HttpReq.responseText;<BR>//at this point you have the entire contents of the page<BR>//in the sHTMLString variable<BR>alert(sHTMLString.length);<BR>return true;<BR>}<BR>&#060;/script&#062;<BR>&#060;form&#062;<BR>&#060;input type="button" name="go" value="Go" onClick="return getPage();"&#062;<BR>&#060;/form&#062;<BR>&#060;/html&#062;<BR><BR>The client side stuff will only work if the client is using IE and the browser sercurity settings are set to allow ActiveX Objects to be instantiated.<BR><BR>Replace "" with whatever page you want to stash in the variable. Parsing out what you want from that point is your job. :-)<BR><BR>HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts