private static async Task <string> ImportFromMtgGoldfish(string url, IReporter reporter) { var web = new HtmlWeb(); reporter.Report("Unraveling skeins..."); HtmlDocument doc = await web.LoadFromWebAsync(url); var decklistBuilder = new StringBuilder(); HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//table[@class='deck-view-deck-table']/tr"); List <HtmlNode> deckNodes = nodes.TakeWhile(node => !node.OuterHtml.Contains("Cards Total")).ToList(); if (nodes == null || !nodes.Any()) { throw new InvalidOperationException("Could not find a valid deck at the URL. Make sure the link provided is pointing to the root of the deck."); } reporter.StartProgress(); for (var i = 0; i < deckNodes.Count; i++) { await Task.Delay(1); reporter.Progress(i, 0, deckNodes.Count); reporter.Report($"Bifurcating the furcate {i}/{deckNodes.Count}"); HtmlNode node = deckNodes[i]; try { HtmlNodeCollection qtyNodes = node.SelectNodes(".//td[@class='deck-col-qty']"); HtmlNodeCollection nameNodes = node.SelectNodes(".//td[@class='deck-col-card']"); if (qtyNodes?.Count != 1 || nameNodes?.Count != 1) { continue; } int qty = int.Parse(qtyNodes[0].InnerText.Trim()); string name = HttpUtility.HtmlDecode(nameNodes[0].InnerText.Trim()); var line = new SearchLine(name, qty); decklistBuilder.AppendLine(line.ToString()); } catch (Exception) { reporter.Report($"Failed to import node #{i} from {url}", true); } } reporter.StopProgress(); return(decklistBuilder.ToString()); }
private void GetChainCode(string pageUrl, string[] chains) { HtmlDocument doc = WebClientUtil.GetHtmlDocument(pageUrl, 180000); HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table"); List <HtmlNode> codeTables = (from table in tables.TakeWhile(table => table.Attributes["summary"] != null) let startTitle = table.SelectSingleNode(".//tr[1]/th[1]").InnerText.Trim() where startTitle.Equals("Issue Name") select table).ToList(); if (codeTables.Count != 2) { string msg = string.Format("Error! Can not get 2 tables for Underlying Basket Bonds from web page: {0}", pageUrl); throw new Exception(msg); } for (int i = 0; i < 2; i++) { GetBasketBondsDetail(codeTables[i], chains[i]); } }