Post by kokenge on Aug 31, 2015 21:17:34 GMT -5
Converting HTML can sometimes be confusing. However with 3 functions it becomes simple.
1. strip$(str$) -- strips all unusable characters from a string
2. tags$(tag$,with$) -- Replaces all HTML tags in tag$ with$ something
3. strRep$(str$,rep$,with$) -- replace (rep$) in string (str$) with$ something..
Example:
Here is a simple routing to turn the weather table into a CSV file...
1. strip$(str$) -- strips all unusable characters from a string
2. tags$(tag$,with$) -- Replaces all HTML tags in tag$ with$ something
3. strRep$(str$,rep$,with$) -- replace (rep$) in string (str$) with$ something..
Example:
Here is a simple routing to turn the weather table into a CSV file...
a$ = httpGet$("http://w1.weather.gov/obhistory/KRDD.html") ' get weather for past 3 days by hour
i = instr(a$,"<tr align=""center"" valign=""top"" bgcolor=""#eeeeee"">") ' find where table begins
a$ = mid$(a$,i)
a$ = strip$(a$) ' strip all unwanted characters
a$ = strRep$(a$,"</tr>",""";"+chr$(13)+"""") ' replace </tr> with <CR> + ending CSV ;
a$ = strRep$(a$,"</td>",""",""") ' replace </td> with CSV separator
a$ = tags$(a$,"") ' replace all the html tags with nothing
a$ = word$(a$,1,"""DateTime(edt)") ' get rid of ending stuff
print a$ ' print CSV table
end
' -----------------------------------------
' strip junk
' -----------------------------------------
FUNCTION strip$(str$)
strip$ = ""
for i = 1 to len(str$)
a$ = MID$(str$,i,1)
a = ASC(a$)
if a > 31 then
if a < 127 then
if a$ <> "'" then
if a$ <> """" then
strip$ = strip$ + a$
end if
end if
end if
end if
next i
END FUNCTION
' --------------------------------
' Replace HTML <tags> with$
' --------------------------------
FUNCTION tags$(tag$,with$)
i = instr(tag$,"<")
j = instr(tag$,">")
WHILE j > i
ln = (j - i) + 1
x$ = mid$(tag$,i,ln)
tag$ = strRep$(tag$,x$,with$)
i = instr(tag$,"<")
j = instr(tag$,">")
WEND
tags$ = tag$
END FUNCTION
' --------------------------------
' string replace rep str with
' --------------------------------
FUNCTION strRep$(str$,rep$,with$)
ln = len(rep$)
ln1 = ln - 1
i = 1
while i <= len(str$)
if mid$(str$,i,ln) = rep$ then
strRep$ = strRep$ + with$
i = i + ln1
else
strRep$ = strRep$ + mid$(str$,i,1)
end if
i = i + 1
WEND
END FUNCTION