Jeff
Jeff

Reputation: 4423

Read html line by line in VBScript

I have a script that will pull the html down and put it into a text or HTML file. I can then parse the text file line by line, but I'd rather either parse the website itself or parse the textstream as I get it. Is this possible using VBS (my scripting languages are limited)?

Code:

dim URL
url = "www.something.com"
set wshshell = wscript.createobject("wscript.shell")
set http = createObject("microsoft.xmlhttp")
on error resume next
http.open "GET", URL, FALSE
http.send
if err.number = 0 then 
    outputFile.writeline http.responsetext
else
    wscript.echo "error " & err.number & ": " & err.description
end if
set wshshell = nothing
set http = nothing

patchStatusFile.close

It works fine if I write to an external HTML file. I was wondering if I HAD to write to a file or can I parse the stream first? ie:

strToLookAt = http.responsetext

do until strToLookAt.atEndOfStream 
    strLine = strToLookAt.readLine 
    if strLine = "the thing I'm looking for" 
        ...do stuff... 
    end if 
loop

Upvotes: 0

Views: 9872

Answers (2)

Rob Moore
Rob Moore

Reputation: 146

Why did no one answer such a simple question?

here is an example of what I do.

dim up_http : up_http = "http://www.metrolyrics.com/Cornography-lyrics-Brad-Paisley.html"
dim xmlhttp : set xmlhttp = createobject("MSXML2.XMLHTTP.6.0")
xmlhttp.open "get", up_http, True
xmlhttp.send
LyricsURL = xmlhttp.responseText
'At this point we have the html from the web page in memory variable LyricsURL

No need to write to any file. You can just process the memory variable line for line.

In this case (script not shown) I have it in a function (get_html). I then process each line of the result of the function looking for a particular strings that mark the beginning and end of the Lyrics. Then I save that result into a variable then I replace and delete characters in this variable.

Upvotes: 1

Jeff
Jeff

Reputation: 4423

Never got an answer. What I decided to do was:

1) Create a temp file where I store the text info. 2) Parse temp file. 3) Delete Temp file.

Not best idea, but in all honesty, this isn't the best script anyway. Just realized there was an "export" button on the SCCM report. I am going to see about utilizing that in a script.

Upvotes: 0

Related Questions