/***************************************************************************** * FUNCTION: ParseLiveData * Description: * Parameters: * pHtmlData - *****************************************************************************/ private void ParseLiveData(MSHTML.IHTMLDocument2 pHtmlData) { MSHTML.IHTMLElement2 docBody; MSHTML.IHTMLElement2 quoteElement, quoteElement2; MSHTML.IHTMLElementCollection searchCollection; List <String> values = null; try { docBody = (MSHTML.IHTMLElement2)pHtmlData.body; //build the array of column headers quoteElement = Helpers.FindHTMLElement(docBody, "div", "id", "quotes_summary_current_data"); if (quoteElement != null) { quoteElement2 = Helpers.FindHTMLElement(quoteElement, "div", "class", "inlineblock"); if (quoteElement2 != null) { searchCollection = quoteElement2.getElementsByTagName("span"); values = Helpers.ParseIHTMLElementCollection(searchCollection); this.live_price.Add(double.Parse(values[0])); this.live_chg = double.Parse(values[1]); this.live_chg_pct = double.Parse(values[2].Replace("%", "")); this.live_timestamps.Add(DateTime.Parse(values[3])); } } } catch (Exception e) { //TBD } }
/***************************************************************************** * FUNCTION: parseHtmlLiveData * Description: * Parameters: * pHtmlData - *****************************************************************************/ public Boolean parseHtmlLiveData(MSHTML.IHTMLDocument2 pHtmlData, String pUrl, String pName) { Boolean success = true; MSHTML.IHTMLElement2 docBody; MSHTML.IHTMLElementCollection searchCollection; MSHTML.IHTMLElementCollection classProperties; MSHTML.IHTMLElementCollection hrefCollection; List <String> columnHeaders; List <String> equityData; string eq_url = ""; try { //Update configuration data this.liveDataUrl = pUrl; if (this.Name == "") { this.Name = pName; } docBody = (MSHTML.IHTMLElement2)pHtmlData.body; //build the array of column headers searchCollection = (MSHTML.IHTMLElementCollection)docBody.getElementsByTagName("th"); columnHeaders = Helpers.ParseIHTMLElementCollection(searchCollection); //build each equity class docBody = (MSHTML.IHTMLElement2)docBody.getElementsByTagName("tbody").item(0); searchCollection = (MSHTML.IHTMLElementCollection)docBody.getElementsByTagName("tr"); if (this.constituents == null) { this.constituents = new List <Equity>(); } foreach (MSHTML.IHTMLElement2 item in searchCollection) { classProperties = item.getElementsByTagName("td"); hrefCollection = item.getElementsByTagName("a"); //Get the full URL address for the particular equity foreach (MSHTML.IHTMLElement href in hrefCollection) { eq_url = (String)href.getAttribute("href"); if (eq_url.Contains("/equities/")) { eq_url = eq_url.Replace("about:", ""); break; } else { eq_url = ""; } } eq_url = (new Uri(pUrl)).DnsSafeHost + eq_url; equityData = Helpers.ParseIHTMLElementCollection(classProperties); UpdateConstituentData(columnHeaders, equityData, eq_url); } success = true; } catch (Exception e) { Console.WriteLine(e.Message); success = false; } return(success); }