public decimal GetProductPrice(string productPageContents, string productCode) { var doc = new HtmlDocument(); doc.LoadHtml(productPageContents); // get the correct XPath for the specific product IProductConfigAccessor productConfigAccessor = AccessorLocator.CreateAccessor <IProductConfigAccessor>(); string xpath = productConfigAccessor.GetXPath(productCode); HtmlNode priceNode = doc.DocumentNode.SelectSingleNode(xpath); decimal price = -1.00m; if (priceNode != null) { decimal.TryParse(WebUtility.HtmlDecode(priceNode.InnerText.Trim().Replace("$", "")), out price); } return(price); }
/// <summary> /// Constructor used for dependency injection /// </summary> public ProductParserEngine(IProductConfigAccessor productConfigAccessor) { Console.WriteLine("ProductParserEngine constructor called"); _productConfigAccessor = productConfigAccessor; }