public static List <DailyCurrency> GetCurrenciesWeb(int curNum, DateTime startDate, DateTime endDate) { List <DailyCurrency> dailyCurrencies = new List <DailyCurrency>(); try { string html = string.Empty; string url = @"https://www.boi.org.il/he/_layouts/boi/handlers/WebPartHandler.aspx?wp=ExchangeRates&lang=he-IL&Currency=" + curNum + "&DateStart=" + startDate.Day + "%2F" + startDate.Month + "%2F" + startDate.Year + "&DateEnd=" + endDate.Day + "%2F" + endDate.Month + "%2F" + endDate.Year; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip; using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { html = reader.ReadToEnd(); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); var rows = doc.DocumentNode.SelectNodes("//div[@id='BoiExchangeRateSearceResults']/table/tr"); for (int i = 1; i < rows.Count; i++) { string curStr = rows[i].ChildNodes[1].InnerText + "," + rows[i].ChildNodes[3].InnerText; dailyCurrencies.Add(DailyCurrency.FromStr(curStr)); } } catch (Exception) { } return(dailyCurrencies); }
public static List <DailyCurrency> GetCurrenciesCsv(string csvFilePath) { return(File.ReadAllLines(csvFilePath).Skip(1).Select(line => DailyCurrency.FromStr(line)).ToList()); }