public async Task <HaloStatModel> GetHalo2StatsFromBungie(string gamerTag) { HaloStatModel haloStatModel = new HaloStatModel(); if (string.IsNullOrWhiteSpace(gamerTag)) { return(await Task.FromResult(haloStatModel)); } else { WebClient client = new WebClient(); string downloadedString = client.DownloadString("https://halo.bungie.net/stats/playerstatshalo2.aspx?player=" + gamerTag); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(downloadedString); string whatUrLookingFor = doc.GetElementbyId("ctl00_mainContent_bnetpgl_identityStrip_div1").InnerHtml; HtmlNodeCollection childNodes = doc.DocumentNode.SelectNodes("//li"); var result = childNodes.Single(x => x.InnerText.Contains("Total Games:") == true); List <string> cleanedResult = GetCleanAndSplitHalo2StatsFromBungie(result.InnerHtml); haloStatModel = ParseHalo2StatsFromBungie(cleanedResult); return(await Task.FromResult(haloStatModel)); } }
private int?ExtractNumber(HtmlNode playerRow) { try { HtmlNodeCollection tdChildNodes = playerRow.SelectNodes("td")[0].ChildNodes; if (!tdChildNodes.Any()) { return(null); } string numberText = tdChildNodes.Single().InnerText; if (string.IsNullOrWhiteSpace(numberText) || !int.TryParse(numberText, out int number)) { return(null); } return(number); } catch (Exception ex) { _logger.LogError(ex, "Failed to extract player's number from a player row."); return(null); } }
private decimal GetPriceFromTable(HtmlNodeCollection tableRows, string fuelName) { var node = tableRows.Single(x => x.SelectSingleNode("td[1]").InnerText == fuelName); var stringPrice = node.SelectSingleNode("td[2]").InnerText; var price = decimal.Parse(stringPrice.Replace(" ", "")); return(PriceCalculator.CalculateFromRateForCubicMeter(price)); }
private static async Task <string> ImportFromStreamdecker(string url, IReporter reporter) { var web = new HtmlWeb(); reporter.Report("Unraveling skeins..."); HtmlDocument doc = await web.LoadFromWebAsync(url); var decklistBuilder = new StringBuilder(); HtmlNodeCollection activeTabNodes = doc.DocumentNode.SelectNodes("//div[@class='display-card-list']"); if (activeTabNodes == null || activeTabNodes.Count != 1) { 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."); } HtmlNodeCollection cardNodes = activeTabNodes.Single().SelectNodes(".//div[@class='card-container']/div[@class='column-wrapper']/div/a[@class='cardLink']"); reporter.StartProgress(); var cardIndex = 0; var qty = 1; while (cardIndex < cardNodes.Count) { try { string name = cardNodes[cardIndex].Attributes.Single(a => a.Name == "data-card-name").Value; qty = 1; while (cardIndex + qty < cardNodes.Count && cardNodes[cardIndex + qty].Attributes.Single(a => a.Name == "data-card-name").Value == name) { qty++; } cardIndex += qty; name = HttpUtility.HtmlDecode(name.Trim()); var line = new SearchLine(name, qty); decklistBuilder.AppendLine(line.ToString()); } catch (Exception) { reporter.Report($"Failed to import all or part of node #{cardIndex} from {url}", true); cardIndex += qty; } } reporter.StopProgress(); return(decklistBuilder.ToString()); }