Forum Moderators: open

Message Too Old, No Replies

Parsing returned html with ASP

Stuck on simple concept. Dope-slap waiting.

         

NorthernStudio

8:58 pm on Jul 5, 2003 (gmt 0)

10+ Year Member



I have a vender that returns a simple product text file. I can display it via the following code:

<%
Response.ContentType="text/html"
Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", [widgets.com...] False
objHTTP.send
f = objHTTP.responseText
response.write f
%>

This works fine to display the returned text to the browser. Rather then send the text to the browser, I need to read the string line-by-line and extract data from specific lines. I've assigned a variable 'f' to objHTTP.responseText and tried to use it with the readline function with no luck.

Error returned for the 'Do While' line: Object required:

I maybe approaching this all wrong. Any help would be very much appreciated. (I can't bother my local ASP guru as she's in the midst of house buying & selling craziness.)
Thanks in advance,

Wayne

The whole (short yet non-functioning) code follows:
<%
Response.ContentType="text/html"
Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")
objHTTP.open "GET", [widgets.com...]
objHTTP.send
f = objHTTP.responseText
response.write f

ctr=0
Do While f.EndOfStream = False
cur_str= f.ReadLine

If ctr=6 Then
search_str="Widget size: "
size_str=Replace(cur_str, search_str, "")
End If

ctr=ctr + 1
Loop

Set objHTTP = nothing
%>

aspdaddy

9:17 am on Jul 6, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think the error is because f is a variant/string and doesnt have EndOfStream or ReadLine Methods.

One way to do this is to move through the string extracting lines by searching for an end of line marker :

currentPos = 1
while ( currentPos <> len( myText) )
' find pos of next end of line marker
myLine = left ( myText, linePos)
currentPos=currentPos+len(myLine)
Wend

NorthernStudio

11:44 pm on Jul 6, 2003 (gmt 0)

10+ Year Member



aspdaddy:

Thanks for your response. Now that I know that the responseText is being read as a single string rather than a text stream, I can simply parse the text by using the Instr function since the data follows the same pattern:
Tite: .... Author: .... ISBN....etc.

Thanks for pointing me in the right direction.

Wayne