protected override ProductPageInfo ParsePage(HtmlNode document) { IEnumerable<HtmlNode> metaTags = document.QuerySelectorAll("meta"); //let if fire a NRE if some element is not found string name = document.FindHiddenField("name").GetAttributeValue("value"); string description = metaTags.First(m => m.GetAttributeValue("property") == "og:description").GetAttributeValue("content"); string imageUrl = metaTags.First(m => m.GetAttributeValue("property") == "og:image").GetAttributeValue("content"); string priceText = document.FindHiddenField("price").GetAttributeValue("value"); return new ProductPageInfo(name, description, Decimal.Parse(priceText, NumberStyles.Currency), imageUrl); }
private string GetValueSomewhereInThePage(HtmlNode document, string[] names, IEnumerable<HtmlNode> metaTags) { string result = null; var possibleNames = names.SelectMany(n => new[] { n, "og:" + n }); var metaField = metaTags.FirstOrDefault(m => m.HasAttribute("property") && possibleNames.Contains(m.GetAttributeValue("property"))); if (metaField == null) { metaField = metaTags.FirstOrDefault(m => m.HasAttribute("name") && possibleNames.Contains(m.GetAttributeValue("name"))); } if (metaField != null) { result = metaField.GetAttributeValue("content"); } if (String.IsNullOrWhiteSpace(result)) { foreach (var name in possibleNames) { var hiddenField = document.FindHiddenField(name); if (hiddenField != null) { result = hiddenField.GetAttributeValue("value"); break; } } } return result; }
protected override ProductPageInfo ParsePage(HtmlNode document) { var metaTags = document.QuerySelectorAll("meta"); //let if fire NRE if some element is not found string name = metaTags.First(m => m.GetAttributeValue("name") == "title").GetAttributeValue("content"); string description = metaTags.First(m => m.GetAttributeValue("name") == "description").GetAttributeValue("content"); string imageUrl = metaTags.First(m => m.GetAttributeValue("property") == "og:image").GetAttributeValue("content"); var priceHidden = document.FindHiddenField("ADD_CART_ITEM<>salePriceAmt"); if (priceHidden == null) { priceHidden = document.FindHiddenField("ADD_CART_ITEM_ARRAY<>salePriceAmt"); } string priceText = priceHidden.GetAttributeValue("value"); return new ProductPageInfo(name, description, Decimal.Parse(priceText, NumberStyles.Currency), imageUrl); }