12-11-2007, 12:20 AM
The 10-Day Forecast, complete.
Macro ( 10 Day Forecast ) Trigger ( @11 )
str s message zipcode url
zipcode="48183" ;;<----------Enter your zipcode
url.from("http://www.weather.com/weather/tenday/" zipcode)
IntGetFile url s
ARRAY(str) a
HtmlTableToArray s 12 a 0 2
int i nTDinRow=8
for i 0 a.len nTDinRow
,message.formata("%s %s %s %s %s %s[]" a[i+1] "[]Hi/Lo:" a[i+5] "[]" a[i+2] "[]-----------------------")
mes message "10-Day Forecast" "sa"Must have function: HtmlTableToArray
Function ( HtmlTableToArray )
;/;
function $HTML VARIANT'tableNameOrIndex [ARRAY(str)&a] [ARRAY(MSHTML.IHTMLElement)&a2] [flags] [str&tableText] ;;flags: 1 get HTML, 2 get all TD elements, including of inner tables
;Gets cells of a HTML table into array.
;HTML - all HTML (page source).
;tableNameOrIndex - table name or 0-based index in the html.
;a - array variable for results. The function creates 1-dimension array where each element is cell text. Can be 0 if not needed.
;a2 - array variable for results. The function creates 1-dimension array where each element is cell object that can be used to get html element within the cell. Can be 0 if not needed.
;tableText - optional str variable that receives whole text of the table. Can be 0 if not needed.
MSHTML.IHTMLDocument2 d; MSHTML.IHTMLDocument3 d3
HtmlParse HTML d d3
IDispatch disp=d3.getElementsByTagName("TABLE").item(tableNameOrIndex); err end "the specified table does not exist"
MSHTML.IHTMLElementCollection cells
if(flags&2)
,MSHTML.IHTMLElement2 t2=disp
,cells=t2.getElementsByTagName("TD")
else
,MSHTML.IHTMLTable2 table=disp
,cells=table.cells
int i nc=cells.length
if(&a) a.create(nc)
if(&a2) a2.create(nc)
for i 0 nc
,MSHTML.IHTMLElement el=cells.item(i)
,if(&a) if(flags&1) a[i]=el.innerHTML; else a[i]=el.innerText
,if(&a2) a2[i]=el
,el=0 ;;without this may be exception in destructors, don't know why
if(&tableText)
,el=disp
,if(flags&1) tableText=el.innerHTML; else tableText=el.innerTextAlso, HtmlParse:
Function ( HtmlParse )
function $HTML [MSHTML.IHTMLDocument2&doc2] [MSHTML.IHTMLDocument3&doc3]
;Creates document object model of HTML.
;HTML - HTML.
;doc2, doc3 - variables that, after calling the function, can be used to get parsed HTML information. Can be omitted or 0.
MSHTML.IHTMLDocument2 d._create(uuidof(MSHTML.HTMLDocument))
ARRAY(VARIANT) a.create(1)
a[0]=HTML
d.write(a)
if(&doc2) doc2=d
if(&doc3) doc3=+d
Taking on Quick Macros one day at a time
