Пример #1
0
        private StockData getDataFromRow(HtmlNode row)
        {
            List<HtmlNode> columns = row.Descendants("td").ToList();

            #region Ugly part of parsing the columns from the site to objects

            string symbol = columns[0].Element("a").InnerText;
            string name = columns[1].Element("a").InnerText;
            double last = double.Parse(columns[2].InnerText);
            string changeString = columns[3].Element("span").InnerText;
            string percentString = columns[4].Element("span").InnerText;
            percentString = percentString.Substring(0, percentString.Length - 1);
            double change = 0;
            double percent = 0;
            if (changeString != UNCHANGED_SYMBOL)
            {
                change = double.Parse(changeString);
                percent = double.Parse(percentString);
            }
            double high = double.Parse(columns[5].InnerText);
            double low = double.Parse(columns[6].InnerText);
            int volume = int.Parse(columns[7].InnerText, System.Globalization.NumberStyles.AllowThousands);
            string time = columns[8].InnerText;

            #endregion

            StockData stock = new StockData()
            {
                Symbol = symbol,
                Name = name,
                Last = last,
                Change = change,
                Percent = percent,
                High = high,
                Low = low,
                Volume = volume,
                Time = time
            };

            return stock;
        }