protected virtual bool GetForecastFor(WalletInvestorDataItem item, WalletInvestorPortalHelper helper) { PortalClient wc = new PortalClient(helper.Chromium); byte[] data = wc.DownloadData(string.Format("https://walletinvestor.com/forecast?currency={0}", item.Name)); if (data == null) { return(false); } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.Load(new MemoryStream(data)); HtmlNode node = doc.DocumentNode.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "currency-desktop-table kv-grid-table table table-hover table-bordered table-striped table-condensed"); if (node == null) { return(false); } HtmlNode body = node.Element("tbody"); List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList(); if (rows.Count == 0) { return(false); } for (int ri = 0; ri < rows.Count; ri++) { HtmlNode row = rows[ri]; HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0"); HtmlNode forecast14 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1"); HtmlNode forecast3Month = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2"); try { string nameText = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim(); if (item.Name != nameText) { continue; } item.Forecast14Day = Convert.ToDouble(CorrectString(forecast14.Element("a").InnerText)); item.Forecast3Month = Convert.ToDouble(CorrectString(forecast3Month.Element("a").InnerText)); if (item.Forecast14Day < Settings.Min14DayChange || item.Forecast3Month < Settings.Min3MonthChange) { return(true); } Get7DayForecastFor(item, name.Element("a").GetAttributeValue("href", ""), helper); return(true); } catch (Exception) { continue; } } return(false); }
private void DownloadDetailedForecast(string coin) { PortalClient wc = new PortalClient(); byte[] data = wc.DownloadData(string.Format("https://walletinvestor.com/forecast?currency={0}", coin)); if (data == null) { return; } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.Load(new MemoryStream(data)); HtmlNode node = doc.DocumentNode.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "currency-desktop-table kv-grid-table table table-hover table-bordered table-striped table-condensed"); if (node == null) { return; } HtmlNode body = node.Element("tbody"); List <HtmlNode> rows = body.Descendants().Where(n => n.GetAttributeValue("data-key", "") != "").ToList(); if (rows.Count == 0) { return; } foreach (HtmlNode row in rows) { HtmlNode name = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "0"); HtmlNode forecast14 = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "1"); HtmlNode forecast3Month = row.Descendants().FirstOrDefault(n => n.GetAttributeValue("data-col-seq", "") == "2"); try { WalletInvestorDataItem item = new WalletInvestorDataItem() { Name = coin }; string nameText = name.Descendants().FirstOrDefault(n => n.GetAttributeValue("class", "") == "detail").InnerText.Trim(); if (item.Name != nameText) { continue; } item.Description = name.InnerText.Remove(name.InnerText.Length - nameText.Length); item.Forecast14Day = Convert.ToDouble(CorrectString(forecast14.Element("a").InnerText)); item.Forecast3Month = Convert.ToDouble(CorrectString(forecast3Month.Element("a").InnerText)); WiItems.Add(item); } catch (Exception) { continue; } } }