Using Microsoft's XMLHTTP Object to Get Data

Results 1 to 2 of 2

Thread: Using Microsoft's XMLHTTP Object to Get Data

  1. #1
    maurice walshe Guest

    Default Using Microsoft's XMLHTTP Object to Get Data

    Hi<BR><BR>Ime trying to use the above article to harvest one of our webpages howeaver the page come out severly messed up?<BR><BR>We are using a lot of style sheets is this what causeing it?<BR><BR>Rgds M<BR>--<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Using Microsoft's XMLHTTP Object to Get D

    No - more than likely it is an encoding problem. Here is a sample vbs file (run using cscript file.vbs that shows how to get a file from a remote using right output - there are several types - one for binary, one for text and one for unicode xml? - have to check documentation for complete run down.)<BR><BR>&#039; Program to retrieve stock symbols and save to a file<BR><BR>Dim quote<BR><BR>quote = getQuote("MSFT")<BR><BR>wscript.echo quote<BR>wscript.echo "Save the quote to a file"<BR><BR>Function getQuote(symbol)<BR><BR> Dim objXmlHttp<BR> Dim strHTML<BR> Dim protocol<BR> Dim host<BR> Dim path<BR> Dim file<BR> Dim tmpQuote<BR> Dim tmp1Quote<BR> <BR> Dim QuoteArray<BR><BR> Dim QuotePath<BR><BR><BR> protocol = "http://"<BR> host = ""<BR> path = "/download/"<BR> file = "javasoft.beans"<BR> querystr = "?SYMBOLS=" & symbol & "&format=nlc"<BR><BR> QuotePath = protocol & host & path & file & querystr<BR><BR> Set objXmlHttp = CreateObject("Msxml2.ServerXMLHTTP")<BR><BR> "GET", QuotePath, False<BR><BR> objXmlHttp.send<BR> &#039; ResponseText is the key here - ResponseXML will munge output of an html file - has to do with char encoding.<BR> tmpQuote = objXMLHttp.responseText<BR> <BR> &#039; Now the data is stored in the variable, lets break it apart and build a formatted string to return<BR> &#039; Lets split it at the carriage return: <BR> <BR> &#039; First - remove the quotes around the data<BR> <BR> tmp1Quote = RmQuote (tmpQuote)<BR> QuoteArray = split(tmp1Quote,",",-1,1) <BR><BR> getQuote = "&#060;span&#062;" & Trim(QuoteArray(0)) & " at " & QuoteArray(1) & "&#060;/span&#062;"<BR> Set objXmlHttp = Nothing<BR> <BR><BR>End Function<BR><BR><BR>Function rmQuote ( instring )<BR><BR> Dim regex, ptrn, repstr, str1<BR> &#039; Look for double quotes and replace with nothing<BR> ptrn = chr(34)<BR> repstr = ""<BR> str1 = instring<BR><BR> set regex = New RegExp<BR> regex.Pattern = ptrn<BR> regex.Global = True<BR> str1 = regex.Replace(str1, repstr)<BR><BR> rmQuote = str1<BR> <BR> set regex = nothing<BR> <BR>End Function

Posting Permissions

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