Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GetHtmlElement
#1
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     Help - how to add the trigger to the macro
Code:
Copy      Help
Htm el1=htm("TD" "Market Cap (intraday)*:" "" win(" Internet Explorer" "IEFrame") 0 0 0x21 5 +3)
but without a browser

Here's my sample code.
Macro Test HTML
Code:
Copy      Help
// 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


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)