vbScript to parse raw web data

Need to develop a vbscript (can't use PowerShell) to do the following:

Open a website which shows only data, no HTML code
Parse first block of data from it

Sample URL would be 'http://sample/data'

Result would be
F|68.3|55.5|-999.9|65.8|62.6|-999.9|74.0|47.4|-999.9|71.9|48.3|-999.9

Need to extract just the value after the 'F|' and the next '|' so this would be 68.3
edrz01Asked:
Who is Participating?
 
Scott Fell, EE MVEConnect With a Mentor Developer & EE ModeratorCommented:
There are two main parts to this. First is pulling in the html from the site. That is easy.  The hard part is pulling out what you need. I am going to give you some sample code I have not touched in over 10 years for an asp/vbscript page. As this is just the vbscript part, you can run it locally as a vbs. If you do that, you can't use response.write though.

It is pretty strait forward. Step 1 is to get the data.  Then step 2 is up to you to figure out how to grab just what you want and you can use various methods including regex which I am not very good at or just finding data between tags as I have done here.
   ' STEP 1 IS TO GRAB THE HTML FROM A WEB PAGE
    url = "http://some_web_site.oom/page.html" ' THE WEB PAGE YOU WANT TO PULL FROM
    
    xmlhttp.open "GET", url, false 
	xmlhttp.setRequestHeader "User-Agent","Thank you for the html"
    xmlhttp.send "" 
    
    ' AT THIS POINT YOU COULD OUTPUT THE HTML CODE YOU JUST PULLED IN WITH
    ' response.write xmlhttp.responseText
    ' OR PLACE IT IN A VARIABLE 
    ' MyVariable = xmlhttp.responseText
    
    ' STEP 2 NOW IT IS UP TO YOU TO STRIP OUT WHAT YOU DON'T WANT 
    
    
    ' ****** ONLY PULL DATA BETWEEN THE FORM TAGS **************
	txtstart= instr(1,xmlhttp.responseText, "<form>",1) 
    txtend= instr(1,xmlhttp.responseText, "</form>",1)
    
    ' ******** START TO BUILD NEW HTML ********************
	response.write("<div id=""testing"">")
	
	theHtml= mid(xmlhttp.responseText, txtstart, txtend-txtstart) ' GET THE HTML BETWEEN FORM TAGS
	
	
    theHtml=replace(theHtml,"<form>","") ' REBUILD THE FORM
	theHtml=replace(theHtml," <div class=""content"">","")
	theHtml=replace(theHtml,"bgcolor=""#0B294D""","bgcolor=""#990000""")
	theHtml=replace(theHtml,"<a href=""testing.aspx","<a target=""_blank"" href=""http://www.testing.com/pages/anotherpage.aspx")
	theHtml=replace(theHtml,"src=""Images","src=""http://www.testing.com/Images")
	
	'  STEP 3 IS TO OUTPUT THE HTML OR YOU COULD STORE IT IN YOUR DATABASE
	response.write theHtml
	response.write("</div><!-- end -->")
	
    set xmlhttp = nothing ' CLOSE IT DOWN

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.