public PriceParserResult Parse() { if (string.IsNullOrEmpty(Content)) { throw new Exception("No content loaded, call Load first."); } var result = new PriceParserResult(); try { var title = GetPropertyValue(@"//*[contains(@property,'og:title')]")?.Trim(); var retailerPartNo = GetPropertyValue(@"//*[contains(@property,'product:retailer_part_no')]")?.Trim(); var price = GetPropertyValue(@"//*[contains(@property,'product:price:amount')]")?.Trim(); var priceNumber = Convert.ToDecimal(price, CultureInfo.InvariantCulture); result.Price = priceNumber; result.ProductNo = retailerPartNo; result.Title = title; result.Proper = priceNumber != 0; } catch (Exception e) { result.Proper = false; throw; } return(result); }
public PriceParserResult Parse() { if (string.IsNullOrEmpty(Content)) { throw new Exception("No content loaded, call Load first."); } var result = new PriceParserResult(); try { var title = GetPropertyValue(@"//*[contains(@property,'og:title')]")?.Trim(); var brand = GetPropertyValue(@"//*[contains(@property,'product:brand')]")?.Trim(); var retailerPartNo = GetPropertyValue(@"//*[contains(@property,'product:retailer_part_no')]")?.Trim(); var price = HtmlDocument.DocumentNode .SelectSingleNode(@"//*/meta[contains(@itemprop,'price')]") .Attributes .FirstOrDefault(a => a.Name == "content") .Value; var priceNumber = Convert.ToDecimal(price, CultureInfo.InvariantCulture); result.Price = priceNumber; result.ProductNo = $"{ brand ?? string.Empty}.{retailerPartNo}"; result.Title = title; result.Proper = priceNumber != 0; } catch (Exception e) { result.Proper = false; throw; } return(result); }
public override PriceParserResult Parse() { if (string.IsNullOrEmpty(Content)) { throw new Exception("No content loaded, call Load first."); } var result = new PriceParserResult(); try { string priceStr = String.Empty; try { priceStr = HtmlDocument.DocumentNode.SelectSingleNode(@"//*[contains(@class,'product-page_short-desc')]/div[contains(., 'Cena')]/span[@class='value']").InnerText; } catch (Exception e) { priceStr = HtmlDocument.DocumentNode.SelectSingleNode(@"//*[contains(@class,'main-price')]").InnerText; } var price = Convert.ToDecimal(priceStr.Replace("zł", String.Empty).Trim(), CultureInfo.GetCultureInfo("pl")); var ean = HtmlDocument.DocumentNode.SelectSingleNode(@"//*[contains(@class,'product-page_short-desc')]/div[contains(., 'EAN')]/span[@class='value']").InnerText; var title = HtmlDocument.DocumentNode.SelectSingleNode(@"//*/h1[contains(@itemprop,'name')]").InnerText?.Trim(); result.Price = price; result.ProductNo = ean; result.Title = title; result.Proper = price != 0; } catch (Exception e) { result.Proper = false; throw; } return(result); }
public PriceParserResult Parse() { if (string.IsNullOrEmpty(Content)) { throw new Exception("No content loaded, call Load first."); } var result = new PriceParserResult(); try { using (var sr = new StringReader(Content)) { var line = sr.ReadLine(); var startParsing = false; var nameParsed = false; while (!string.IsNullOrEmpty(line)) { if (line.Contains("\"aggregateRating\":", StringComparison.InvariantCulture) || line.Contains("\"isRelatedTo\":", StringComparison.InvariantCulture)) { break; } if (!startParsing && line.Contains("\"description\":", StringComparison.InvariantCulture)) { startParsing = true; line = sr.ReadLine(); } if (startParsing) { if (!nameParsed && line.Contains("\"name\":", StringComparison.InvariantCulture)) { result.Title = GetValue(line); nameParsed = true; } else if (line.Contains("\"gtin13\":", StringComparison.InvariantCulture)) { result.ProductNo = GetValue(line); } else if (line.Contains("\"price\":", StringComparison.InvariantCulture)) { var priceStr = GetValue(line).Replace(".", ","); result.Price = Convert.ToDecimal(priceStr, _polishCulture); } } line = sr.ReadLine(); } } result.Proper = result.Price != 0; } catch (Exception e) { result.Proper = false; throw; } return(result); }