public static void DownloadFinancial(StockSerie stockSerie)
        {
            if (stockSerie.Financial != null && stockSerie.Financial.DownloadDate.AddDays(7) > DateTime.Now) return;

            StockFinancial financial = new StockFinancial();
            try
            {
                string shortName = stockSerie.StockGroup == StockSerie.Groups.ALTERNEXT ? "EP" : "P";
                shortName += stockSerie.ShortName;
                DownloadFinancialSummary(financial, shortName);

                string url = "http://www.boursorama.com/bourse/profil/profil_finance.phtml?symbole=1r$ShortName".Replace("$ShortName", shortName);
                StockWebHelper swh = new StockWebHelper();
                string html = swh.DownloadHtml(url);

                WebBrowser browser = new WebBrowser();
                browser.ScriptErrorsSuppressed = true;
                browser.DocumentText = html;
                browser.Document.OpenNew(true);
                browser.Document.Write(html);
                browser.Refresh();

                HtmlDocument doc = browser.Document;

                var divs = doc.GetElementsByTagName("div").Cast<HtmlElement>();
                foreach (var div in divs)
                {
                    if (div.InnerText != null && div.InnerText.StartsWith("Compte de"))
                    {
                        Console.WriteLine(div.InnerText);
                        var tables = div.GetElementsByTagName("table").Cast<HtmlElement>();
                        financial.IncomeStatement = getTableData(tables.First());
                        break;
                    }
                }
                foreach (var div in divs)
                {
                    if (div.InnerText != null && div.InnerText.StartsWith("Bilan"))
                    {
                        Console.WriteLine(div.InnerText);
                        var tables = div.GetElementsByTagName("table").Cast<HtmlElement>();
                        financial.BalanceSheet = getTableData(tables.First());
                        break;
                    }
                }
                foreach (var div in divs)
                {
                    if (div.InnerText != null && div.InnerText.StartsWith("Chiffres d'affaires"))
                    {
                        Console.WriteLine(div.InnerText);
                        var tables = div.GetElementsByTagName("table").Cast<HtmlElement>();
                        financial.Quaterly = getTableData(tables.First());
                        break;
                    }
                }

                financial.DownloadDate = DateTime.Now;
                stockSerie.Financial = financial;
                stockSerie.SaveFinancial();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        //public static void DownloadFinancial2(StockSerie stockSerie)
        //{
        //    if (stockSerie.StockAnalysis.Financial != null && stockSerie.StockAnalysis.Financial.DownloadDate.AddDays(7) > DateTime.Now) return;
        //    string url = "http://www.abcbourse.com/analyses/chiffres.aspx?s=$ShortNamep".Replace("$ShortName", stockSerie.ShortName);
        //    url = "http://www.boursorama.com/bourse/profil/profil_finance.phtml?symbole=1rP$ShortName".Replace("$ShortName", stockSerie.ShortName);
        //    StockWebHelper swh = new StockWebHelper();
        //    string html = swh.DownloadHtml(url);
        //    WebBrowser browser = new WebBrowser();
        //    browser.ScriptErrorsSuppressed = true;
        //    browser.DocumentText = html;
        //    browser.Document.OpenNew(true);
        //    browser.Document.Write(html);
        //    browser.Refresh();
        //    HtmlDocument doc = browser.Document;
        //    HtmlElementCollection tables = doc.GetElementsByTagName("div");
        //    List<List<string>> data = new List<List<string>>();
        //    StockFinancial financial = new StockFinancial();
        //    HtmlElement tbl = tables.Cast<HtmlElement>().FirstOrDefault(t => t.InnerText.StartsWith("Marché"));
        //    if (tbl != null)
        //    {
        //        //ParseFinancialGeneral(stockSerie, financial, tbl);
        //    }
        //    bool found = false;
        //    int count = 0;
        //    foreach (HtmlElement table in tables)
        //    {
        //        if (found)
        //        {
        //            switch (count)
        //            {
        //                case 0:
        //                    financial.IncomeStatement = getTableData(table);
        //                    count++;
        //                    break;
        //                case 1:
        //                    financial.BalanceSheet = getTableData(table);
        //                    count++;
        //                    break;
        //                case 2:
        //                    financial.Ratios = getTableData(table);
        //                    count++;
        //                    break;
        //                case 3:
        //                    financial.Quaterly = getTableData(table);
        //                    count++;
        //                    break;
        //            }
        //        }
        //        else
        //        {
        //            found = table.InnerText.StartsWith("Compte de");
        //        }
        //    }
        //    if (found)
        //        tbl = tables.Cast<HtmlElement>().FirstOrDefault(t => t.InnerText.StartsWith("Compte"));
        //    if (tbl != null)
        //    {
        //        ParseFinancialDetails(stockSerie, financial, tbl);
        //    }
        //}
        public static void DownloadFinancialSummary(StockFinancial financial, string shortName)
        {
            string url = "http://www.boursorama.com/bourse/profil/resume_societe.phtml?symbole=1r$ShortName".Replace("$ShortName", shortName);
            StockWebHelper swh = new StockWebHelper();
            string html = swh.DownloadHtml(url);

            WebBrowser browser = new WebBrowser();
            browser.ScriptErrorsSuppressed = true;
            browser.DocumentText = html;
            browser.Document.OpenNew(true);
            browser.Document.Write(html);
            browser.Refresh();

            HtmlDocument doc = browser.Document;

            var divs = doc.GetElementsByTagName("div").Cast<HtmlElement>();
            foreach (var div in divs)
            {
                if (div.InnerText != null && div.InnerText.StartsWith("Nombre de titres"))
                {
                    var list = div.InnerText.Replace(Environment.NewLine, "|");
                    var split = list.Split('|');
                    var nbTitres = split[0].Split(':')[1].Replace(" ", "");
                    financial.ShareNumber = long.Parse(nbTitres);
                    financial.Coupon = split.First(l => l.StartsWith("Dern")).Split(':')[1].Trim();
                    financial.Sector = split.First(l => l.StartsWith("Secteur")).Split(':')[1].Trim();
                    financial.PEA = split.First(l => l.Contains("PEA")).Split(':')[1].Trim();
                    financial.SRD = split.First(l => l.Contains("SRD")).Split(':')[1].Trim();
                    financial.Indices = split.First(l => l.StartsWith("Indice")).Split(':')[1].Trim();
                    break;
                }
            }
            foreach (var div in divs)
            {
                if (div.InnerText != null && div.InnerText.StartsWith("Prévisions des analystes"))
                {

                    var tables = div.GetElementsByTagName("table").Cast<HtmlElement>();
                    var previsions = getTableData(tables.First());

                    var dividendLine = previsions.FirstOrDefault(l => l[0] == "Dividende");
                    if (dividendLine != null)
                    {
                        float dividend = 0;
                        float.TryParse(dividendLine[1], out dividend);
                        financial.Dividend = dividend;
                    }

                    break;
                }
            }
            //foreach (var div in divs)
            //{
            //    if (div.InnerText != null && div.InnerText.StartsWith("Activité"))
            //    {
            //        Console.WriteLine(div.InnerText);
            //        financial.Activity = div.InnerHtml;
            //        break;
            //    }
            //}
        }
        private static void ParseFinancialDetails(StockSerie stockSerie, StockFinancial financial, HtmlElement table)
        {
            HtmlElementCollection tables = table.GetElementsByTagName(("table"));
            foreach (HtmlElement tbl in tables)
            {

            }
        }