01-21-2010, 12:52 AM
I want to get an HTML element from an adjacent element without waiting for IE to process javascript ads. I'm using HtmlDoc.GetHtmlElement to find the reference element, but it only works if I already know the index number. How can I search an element based on the contents of the tag? Kind of like doing
Macro Yahoo Key Statistics2
Trigger AF8
but without a browser
Here's my sample code.
Macro Test HTML
Macro Yahoo Key Statistics2
Trigger AF8

Htm el1=htm("TD" "Market Cap (intraday)*:" "" win(" Internet Explorer" "IEFrame") 0 0 0x21 5 +3)
Here's my sample code.
Macro Test HTML
// Download the raw HTML to text
str url = "http://finance.yahoo.com/q/ks?s=MSFT"
str s
IntGetFile(url s)
// strip out the javascript
s.replacerx("[\r\n]+")
s.replacerx("<script.*>.*</script>" "" RX_UNGREEDY)
// Locate the "Market Cap" element
HtmlDoc hd.InitFromText(s)
MSHTML.IHTMLElement el=hd.GetHtmlElement("td" 21)
;MSHTML.IHTMLElement el=hd.GetHtmlElement("td" "Market Cap (intraday)")
if(!el) end "element not found"
out el.innerText
out el.sourceIndex
int MCInd = el.sourceIndex
// Get the Market Cap number (3rd next element)
MSHTML.IHTMLElement el2=hd.GetHtmlElement("" MCInd+3)
if(!el2) end "element not found"
out el2.innerText