public async Task <WatchedBeer> ProductFromProductPage(BasicProduct basicProduct) { var client = Client(); var html = await client.GetStringAsync(basicProduct.LinkToProductPage); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(html); var productInfo = htmlDoc.DocumentNode.FirstElementWithClass("div", "product__all-info"); var siblingOfElementStartingWithInnerText = productInfo.SiblingOfElementStartingWithInnerText("dt", "Alkoholprosent"); var alcohol = siblingOfElementStartingWithInnerText?.InnerText.ExtractDecimal(); if (!alcohol.HasValue) { return(null); } var beerType = productInfo.SiblingOfElementStartingWithInnerText("dt", "Varetype")?.InnerText?.Split(',').LastOrDefault()?.Trim().SafeSubstring(64); return(new WatchedBeer { Name = htmlDoc.DocumentNode.FirstElementWithClass("div", "product")?.Descendants("h1").First().InnerText.RemoveEmptyCharacters().SafeSubstring(256), AlcoholPercentage = alcohol.Value, Type = beerType, //Brewery = productInfo.SiblingOfElementStartingWithInnerText("dt", "Produsent")?.InnerText, //Country = productInfo.SiblingOfElementStartingWithInnerText("dt", "Land")?.InnerText.RemoveEmptyCharacters().Split(',').First(), //Volume = (htmlDoc.DocumentNode.FirstElementWithClass("span", "product__amount")?.InnerText.ExtractDecimal() ?? 0) / 100, MaterialNumber = basicProduct.ProductNumber, Price = htmlDoc.DocumentNode.FirstElementWithClass("span", "product__price")?.InnerText.ExtractDecimal() ?? 0, BeerCategory = WatchedBeer.Category(beerType) }); }
private static BeerCategory BeerCategoryFromQuery(string query) { var beerCategory = WatchedBeer.Category(query); if (beerCategory == BeerCategory.Unknown) { var enumValue = query.DehumanizeTo(typeof(BeerCategory), OnNoMatch.ReturnsNull); if (enumValue != null) { return((BeerCategory)enumValue); } } return(beerCategory); }