public static ProductDto ToDto(BusinessLayer.Product product) { return(new ProductDto { Id = product.Id, Name = product.Name, Price = product.Price, IdCategory = product.Category }); }
private void btnDelete(object sender, EventArgs e) { //deleting record (customer)............. var delCustomerProduct = new BusinessLayer.CustomerProduct(Convert.ToInt32(customerProductId.Text)); int CusId = delCustomerProduct.CustomerId; int PrdId = delCustomerProduct.ProductId; delCustomerProduct.Delete(); var delCustomer = new BusinessLayer.Customer(CusId); delCustomer.Delete(); var delProduct = new BusinessLayer.Product(PrdId); delProduct.Delete(); clearForm(); }
private void btnUpdate(object sender, EventArgs e) { //it is a button which is updating data of customer and product.. we give cutomerProductId through it, customer and product change. var customerProduct = new BusinessLayer.CustomerProduct(Convert.ToInt32(customerProductId.Text)); int cusId = customerProduct.CustomerId; int prdId = customerProduct.ProductId; var customer = new BusinessLayer.Customer(cusId); customer.FirstName = firstName.Text; customer.LastName = lastName.Text; customer.Save(); var product = new BusinessLayer.Product(prdId); product.ProductName = productName.Text; product.SaleCost = Convert.ToInt32(saleCost.Text); product.WholesaleCost = Convert.ToInt32(wholeSaleCost.Text); product.Save(); MessageBox.Show("Data Updated Successfully"); clearForm(); }
private void btnAdd(object sender, EventArgs e) { // it is a button which is adding data into a database enterData(); var customer = new BusinessLayer.Customer(); var product = new BusinessLayer.Product(); var purchases = new BusinessLayer.CustomerProduct(); customer.FirstName = firstName.Text; customer.LastName = lastName.Text; customer.Save(); product.ProductName = productName.Text; product.SaleCost = Convert.ToDecimal(saleCost.Text); product.WholesaleCost = Convert.ToDecimal(wholeSaleCost.Text); product.Save(); purchases.CustomerId = customer.CustomerId; purchases.ProductId = product.ProductId; purchases.Save(); MessageBox.Show("Data Updated Successfully"); clearForm(); }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title if (_doc.DocumentNode.SelectNodes("//h1[@class=\"productDescLarge\"]") != null) product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//h1[@class=\"productDescLarge\"]")[0].InnerText.Trim()); else WriteLogEvent(url, "title not found"); #endregion title #region price if (_doc.DocumentNode.SelectNodes("//span[@class=\"productPriceLarge\"]") != null) product.Price = _doc.DocumentNode.SelectNodes("//span[@class=\"productPriceLarge\"]")[0].InnerText.Replace("$", "").Trim(); else { product.Price = "0"; WriteLogEvent(url, "Price not found"); } #endregion price #region Brand try { if (product.Name.Length > 0) { product.Brand = product.Name.Substring(0, product.Name.IndexOf(' ')); product.Manufacturer = product.Name.Substring(0, product.Name.IndexOf(' ')); product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } else { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } } catch { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } #endregion Brand #region Category if (_doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_lnkMoreCatetory\"]") != null) { try { string Category = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_lnkMoreCatetory\"]")[0].InnerText); if (Category.Contains("->")) Category = Category.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries)[0]; product.Category ="FDCA"+ Category.Trim(); } catch { WriteLogEvent(url, "Category not found"); } } else WriteLogEvent(url, "Category not found"); #endregion Category product.Currency = "CAD"; #region description string Description = ""; var allElementsWithClassFloat = _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblSpecification\"]"); if (allElementsWithClassFloat != null) { foreach (HtmlNode node in allElementsWithClassFloat) { Description = Description + " " + node.InnerText.Trim(); } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")).Replace("factorydirect.ca", ""); } else WriteLogEvent(url, "Description not found"); #endregion description #region BulletPoints string Feature = ""; string Bullets = ""; HtmlNodeCollection collection = _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblSpecification\"]"); if (collection != null) { int PointCounter = 1; foreach (HtmlNode node in collection) { try { Feature = node.InnerText; if (Feature.Length > 480) Feature = Feature.Substring(0, 480); if (Bullets.Length + Feature.Length + 2 <= PointCounter * 480) Bullets = Bullets + Feature + ". "; else { Bullets = Bullets + "@@" + Feature + ". "; PointCounter++; } } catch { } } if (!string.IsNullOrEmpty(Bullets)) Bullets = Bullets.Trim().Replace("factorydirect.ca", ""); } else WriteLogEvent(url, "BulletPoints not found"); if (Bullets.Length > 0) { Bullets = Removeunsuaalcharcterfromstring(StripHTML(Bullets).Trim()); string[] BulletPoints = Bullets.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < BulletPoints.Length; i++) { if (i == 0) product.Bulletpoints1 = BulletPoints[i].ToString(); if (i == 1) product.Bulletpoints2 = BulletPoints[i].ToString(); if (i == 2) product.Bulletpoints3 = BulletPoints[i].ToString(); if (i == 3) product.Bulletpoints4 = BulletPoints[i].ToString(); if (i == 4) product.Bulletpoints5 = BulletPoints[i].ToString(); } } if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; if (_doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_ProductImageHyperLink\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_ProductImageHyperLink\"]")[0].Attributes) { if (attr.Name == "href") Images = attr.Value.Trim(); } } else if (_doc.DocumentNode.SelectNodes("//img[@id=\"ctl00_MainBodyContent_imgProduct\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//img[@id=\"ctl00_MainBodyContent_imgProduct\"]")[0].Attributes) { if (attr.Name == "src") Images = attr.Value.Trim(); } } else WriteLogEvent(url, "Main Images not found"); product.Image = Images; #endregion Image #region sku if (_doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblProductCode\"]") != null) { product.SKU = "FDCA" + _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblProductCode\"]")[0].InnerText.Trim(); product.parentsku = "FDCA" + _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblProductCode\"]")[0].InnerText.Trim(); } #endregion sku product.Isparent = true; product.Stock = "0"; if (_doc.DocumentNode.SelectNodes("//input[@id=\"ctl00_MainBodyContent_btnAdd\"]") != null) product.Stock = "1"; product.URL = url; if (product.Brand.ToUpper() != "SOLOGEAR") Products.Add(product); } catch { } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title if (_doc.DocumentNode.SelectNodes("//h1[@itemprop=\"name\"]") != null) product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//h1[@itemprop=\"name\"]")[0].InnerText.Trim()); else WriteLogEvent(url, "title not found"); #endregion title #region price if (_doc.DocumentNode.SelectNodes("//span[@itemprop=\"offers\"]/span[@itemprop=\"price\"]") != null) { decimal Price = 0; decimal.TryParse(_doc.DocumentNode.SelectNodes("//span[@itemprop=\"offers\"]/span[@itemprop=\"price\"]")[0].InnerText.ToLower().Replace("$", "").Replace("ca", "").Trim(), out Price); product.Price = Price.ToString(); if (Price == 0) WriteLogEvent(url, "Price not found"); } else if (_doc.DocumentNode.SelectNodes("//span[@itemprop=\"price\"]") != null) { decimal Price = 0; decimal.TryParse(_doc.DocumentNode.SelectNodes("//span[@itemprop=\"price\"]")[0].InnerText.ToLower().Replace("$", "").Replace("ca", "").Trim(), out Price); product.Price = Price.ToString(); if (Price == 0) WriteLogEvent(url, "Price not found"); } else { product.Price = "0"; WriteLogEvent(url, "Price not found"); } #endregion price #region Brand if (_doc.DocumentNode.SelectNodes("//div[@class=\"product-manufacturer\"]//a") != null) { product.Brand = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"product-manufacturer\"]//a")[0].InnerText.Replace("by:", "").Replace("by :", "").Trim()); product.Manufacturer = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"product-manufacturer\"]//a")[0].InnerText.Replace("by:", "").Replace("by :", "").Trim()); if (product.Brand == "") { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; WriteLogEvent(url, "Brand not found"); } } else { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; WriteLogEvent(url, "Brand not found"); } #endregion Brand #region Category product.Category = Category; #endregion Category product.Currency = "CAD"; #region description string Description = ""; if (_doc.DocumentNode.SelectNodes("//div[@class=\"box-collateral box-description\"]") != null) { foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//div[@class=\"box-collateral box-description\"]")) { Description = Description + " " + node.InnerText.Trim(); } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } else WriteLogEvent(url, "Description not found"); #endregion description #region BulletPoints string Feature = ""; string Bullets = ""; HtmlNodeCollection collection = _doc.DocumentNode.SelectNodes("//table[@id=\"product-attribute-specs-table\"]"); if (collection != null) { string Header = ""; string Value = ""; int PointCounter = 1; HtmlNodeCollection collection1 = _doc.DocumentNode.SelectNodes(".//td"); HtmlNodeCollection collection2 = _doc.DocumentNode.SelectNodes(".//th"); if (collection1 != null && collection2 != null) { int propCounter = 0; foreach (HtmlNode node in collection1) { try { Header = System.Net.WebUtility.HtmlDecode(collection2[propCounter].InnerText.Trim()); Value = System.Net.WebUtility.HtmlDecode(node.InnerText.Trim()); if (Value != "") { if (Header.ToUpper() == "MANUFACTURER PART NUMBER") { Value = Value.Trim(); product.ManPartNO = Value; } if (Header.ToLower() == "upc") { Value = Regex.Replace(Value, @"[^\d]", String.Empty); product.UPC = Value; } else if (Header.ToUpper() == "AVAILABILITY") { Feature = " " + Header + " " + Value; if (Feature.Length > 480) Feature = Feature.Substring(0, 480); if (Bullets.Length + Feature.Length + 2 <= PointCounter * 480) Bullets = Bullets + Feature + ". "; else { Bullets = Bullets + "@@" + Feature + ". "; PointCounter++; } } } } catch { } propCounter++; } } else WriteLogEvent(url, "Bulepoints not found"); if (!string.IsNullOrEmpty(Bullets)) Bullets = Bullets.Trim(); } else WriteLogEvent(url, "BulletPoints not found"); if (Bullets.Length > 0) { Bullets = Removeunsuaalcharcterfromstring(StripHTML(Bullets).Trim()); string[] BulletPoints = Bullets.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < BulletPoints.Length; i++) { if (i == 0) product.Bulletpoints1 = BulletPoints[i].ToString(); if (i == 1) product.Bulletpoints2 = BulletPoints[i].ToString(); if (i == 2) product.Bulletpoints3 = BulletPoints[i].ToString(); if (i == 3) product.Bulletpoints4 = BulletPoints[i].ToString(); if (i == 4) product.Bulletpoints5 = BulletPoints[i].ToString(); } } if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; HtmlNodeCollection imgCollection = _doc.DocumentNode.SelectNodes("//div[@id=\"more-view\"]"); if (imgCollection != null) { HtmlNodeCollection imgCollection1 = imgCollection[0].SelectNodes(".//a"); foreach (HtmlNode node in imgCollection1) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "href") Images = Images + attr.Value.Trim() + ","; } } } else WriteLogEvent(url, "Main Images not found"); if (Images.Length > 0) Images = Images.Substring(0, Images.Length - 1); product.Image = Images; #endregion Image product.Isparent = true; #region sku if (_doc.DocumentNode.SelectNodes("//p[@class=\"sku\"]") != null) { product.SKU = "HTGM" + _doc.DocumentNode.SelectNodes("//p[@class=\"sku\"]")[0].InnerText.Replace("SKU:", "").Replace("sku:", "").Replace("Sku:", "").Trim(); product.parentsku = "HTGM" + _doc.DocumentNode.SelectNodes("//p[@class=\"sku\"]")[0].InnerText.Replace("SKU:", "").Replace("sku:", "").Replace("Sku:", "").Trim(); } else WriteLogEvent(url, "SKU not found"); #endregion sku #region stock product.Stock = "0"; if (_doc.DocumentNode.SelectNodes("//span[@itemprop=\"availability\"]") != null) { if (_doc.DocumentNode.SelectNodes("//span[@itemprop=\"availability\"]")[0].InnerText.Trim().ToLower() == "in stock") product.Stock = "1"; } else WriteLogEvent(url, "stock not found"); #endregion stock product.URL = url; if (product.Brand.ToUpper() != "SOLOGEAR") Products.Add(product); } catch(Exception exp) { WriteLogEvent(url, "Issue accured in reading product info from given product url. exp: " + exp.Message); } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title HtmlNodeCollection formColl = _doc.DocumentNode.SelectNodes("//meta[@property=\"og:title\"]"); if (formColl != null) { foreach (HtmlAttribute attr in formColl[0].Attributes) { if (attr.Name == "content") product.Name = System.Net.WebUtility.HtmlDecode(attr.Value).Trim(); } } else if (_doc.DocumentNode.SelectNodes("//div[@class=\"product-name\"]/h1") != null) product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"product-name\"]/h1")[0].InnerText).Trim(); else WriteLogEvent(url, "title not found"); #endregion title #region Price if (_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]") != null) { double Price = 0; string priceString = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).Replace("$", "").Trim(); double.TryParse(priceString, out Price); if (Price != 0) product.Price = Price.ToString(); //System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).re; else WriteLogEvent(url, "Price not found"); } else WriteLogEvent(url, "Price not found"); #endregion Price #region Brand product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; #endregion Brand #region Category product.Category = Category; #endregion Category product.Currency = "CAD"; #region description string Description = ""; string BulletPoints = ""; HtmlNodeCollection desCollection = _doc.DocumentNode.SelectNodes("//ul[@class=\"slides\"]/li"); if (desCollection != null) { try { foreach (HtmlNode node in desCollection) { if (node.InnerText.ToLower().Contains("overview")) Description = Description + Removeunsuaalcharcterfromstring(StripHTML(node.InnerText).Trim() + " "); else if (node.InnerText.ToLower().Contains("specifications")) { if (node.SelectNodes(".//tr") != null) { foreach (HtmlNode node1 in node.SelectNodes(".//tr")) { if (node1.SelectNodes(".//td") != null) { string Header = ""; string Value = ""; try { Header = node1.SelectNodes(".//th")[0].InnerText.Trim(); Value = node1.SelectNodes(".//td")[0].InnerText.Trim(); if (Header.ToLower() == "brand") if (Value.ToLower() != "no") { product.Manufacturer = Value; product.Brand = Value; } BulletPoints = BulletPoints + Header + " " + Value + " "; } catch { } } } } } } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } catch { WriteLogEvent(url, "Description not found"); } if (!string.IsNullOrEmpty(BulletPoints.Trim())) product.Bulletpoints1 = BulletPoints; } else WriteLogEvent(url, "Description not found"); #endregion description #region BulletPoints if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; HtmlNodeCollection imgCollection = _doc.DocumentNode.SelectNodes("//img[@class=\"gallery-image\"]"); if (imgCollection != null) { foreach (HtmlNode node in imgCollection) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "src") Images = Images + attr.Value.Trim() + ","; } } } else if (_doc.DocumentNode.SelectNodes("//img[@class=\"gallery-image visible\"]") != null) { foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//img[@class=\"gallery-image visible\"]")) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "src") Images = Images + attr.Value.Trim() + ","; } } } else WriteLogEvent(url, "Main Images not found"); if (Images.Length > 0) Images = Images.Substring(0, Images.Length - 1); product.Image = Images; #endregion Image product.Isparent = true; #region sku string sku = ""; if (_doc.DocumentNode.SelectNodes("//input[@name=\"product\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//input[@name=\"product\"]")[0].Attributes) { if (attr.Name == "value") { product.SKU = "HCKYSUP" + attr.Value.Trim(); product.parentsku = "HCKYSUP" + attr.Value.Trim(); sku = product.SKU; } } } else WriteLogEvent(url, "SKU not found"); #endregion sku #region stock product.Stock = "0"; if (_doc.DocumentNode.SelectNodes("//span[@id=\"stock-availability\"]") != null) { if (_doc.DocumentNode.SelectNodes("//span[@id=\"stock-availability\"]")[0].InnerText.ToLower() == "in stock") product.Stock = "1"; } #endregion stock product.URL = url; #region Variation bool _isVariantProduct = false; bool _isKitProduct = false; string attributeScript = ""; string attributeCombScript = ""; HtmlNodeCollection collOption = _doc.DocumentNode.SelectNodes("//div[@class=\"product-options\"]"); if (collOption != null) { _isVariantProduct = true; if (collOption[0].SelectNodes(".//label") != null) { if (collOption[0].SelectNodes(".//label").Count > 2) _isKitProduct = true; else { foreach (HtmlNode node in collOption[0].SelectNodes(".//label")) { if (!variationTheme.Contains(node.InnerText.Trim().ToLower())) { _isKitProduct = true; break; } } } } else { _isKitProduct = true; WriteLogEvent(url, "option heading Not found, due to which product marked as kit. For more information please check code if(collOption[0].SelectNodes(\".//label\")!=null)"); } } if (!_isKitProduct) { HtmlNodeCollection collScript = _doc.DocumentNode.SelectNodes("//script"); if (collScript != null) { foreach (HtmlNode scriptNode in collScript) { if (scriptNode.InnerText.ToLower().Contains("spconfig")) { string script = scriptNode.InnerText.ToLower(); _isVariantProduct = true; try { attributeScript = script.Substring(0, script.IndexOf("var allperm")).Replace("var allperm", "").Replace("\"176\":{", "\"skate_width\":{").Replace("\"197\":{", "\"size_skates\":{").Replace("\"92\":{", "\"color\":{").Replace("\"136\":{", "\"size\":{").Replace("\"198\":{", "\"size\":{").Replace("\"199\":{", "\"size\":{").Trim(); attributeScript = attributeScript.Substring(attributeScript.IndexOf("(")).Replace(");", "").Replace("(", ""); attributeCombScript = script.Substring(script.IndexOf("var allperm")).Replace("var allperm", "").Trim(); } catch { _isKitProduct = true; WriteLogEvent(url, "script tag is not in well format, due to which this product marked as kit"); } break; } } } else { _isKitProduct = true; WriteLogEvent(url, "script tag is not found, due to which product marked as kit"); } } if (!_isKitProduct && !_isVariantProduct) Products.Add(product); else if (!_isKitProduct && _isVariantProduct) { try { string color = ""; string size = ""; string stock = ""; string saleInfo = ""; string price = ""; string filterString = ""; RootObject deserializedProduct = JsonConvert.DeserializeObject<RootObject>(attributeScript.Trim()); List<Option2> option1 = deserializedProduct.attributes.color == null ? deserializedProduct.attributes.skate_width == null ? null : deserializedProduct.attributes.skate_width.options : deserializedProduct.attributes.color.options; List<Option2> option2 = deserializedProduct.attributes.size == null ? deserializedProduct.attributes.size_skates == null ? null : deserializedProduct.attributes.size_skates.options : deserializedProduct.attributes.size.options; int variantCounter = 1; if (option1 != null || option2 != null) { if (option1 == null) { try { foreach (Option2 sizeOption in option2) { bool isStockStringExist = true; try { filterString = attributeCombScript.Substring(attributeCombScript.IndexOf("\"" + sizeOption.id + "\":{")).ToLower(); } catch { isStockStringExist = false; } if (isStockStringExist) { BusinessLayer.Product sizeProduct = new BusinessLayer.Product(); sizeProduct = (BusinessLayer.Product)product.Clone(); sizeProduct.parentsku = sku + "-parent"; sizeProduct.SKU = sku + "-" + sizeOption.id; sizeProduct.Size = sizeOption.label; #region getAvailability stock = filterString.Substring(filterString.IndexOf("\"availability\"")).Replace("\"availability\"", ""); stock = stock.Substring(0, stock.IndexOf(",")); saleInfo = filterString.Substring(filterString.IndexOf("\"saleinfo\"")).Replace("\"saleinfo\"", ""); saleInfo = saleInfo.Substring(0, saleInfo.IndexOf(",")); if (stock.Contains("normal") && saleInfo.Contains("in stock")) sizeProduct.Stock = "1"; else sizeProduct.Stock = "0"; price = filterString.Substring(filterString.IndexOf("\"specialprice\"")).Replace("\"specialprice\"", ""); price = price.Substring(0, price.IndexOf(",")).Replace("$", ""); double specialPrice = 0; double.TryParse(price, out specialPrice); if (specialPrice != 0) sizeProduct.Price = specialPrice.ToString(); else { WriteLogEvent(url, "issue accured in getting price info for variants"); } if (variantCounter != 1) sizeProduct.Isparent = false; Products.Add(sizeProduct); #endregion getAvailability variantCounter++; } else { WriteLogEvent(url, "Stock string not find for size:" + sizeOption.label); } } } catch { WriteLogEvent(url, "issue accured in getting stock etc info for variants"); } } else if (option2 == null) { try { foreach (Option2 colorOption in option1) { bool isStockStringExist = true; try { filterString = attributeCombScript.Substring(attributeCombScript.IndexOf("\"" + colorOption.id + "\":{")).ToLower(); } catch { isStockStringExist = false; } if (isStockStringExist) { BusinessLayer.Product sizeProduct = new BusinessLayer.Product(); sizeProduct = (BusinessLayer.Product)product.Clone(); sizeProduct.parentsku = sku + "-parent"; sizeProduct.SKU = sku + "-" + colorOption.id; sizeProduct.Color = colorOption.label; #region getAvailability filterString = attributeCombScript.Substring(attributeCombScript.IndexOf("\"" + colorOption.id + "\":{")).ToLower(); stock = filterString.Substring(filterString.IndexOf("\"availability\"")).Replace("\"availability\"", ""); stock = stock.Substring(0, stock.IndexOf(",")); saleInfo = filterString.Substring(filterString.IndexOf("\"saleinfo\"")).Replace("\"saleinfo\"", ""); saleInfo = saleInfo.Substring(0, saleInfo.IndexOf(",")); if (stock.Contains("normal") && saleInfo.Contains("in stock")) sizeProduct.Stock = "1"; else sizeProduct.Stock = "0"; price = filterString.Substring(filterString.IndexOf("\"specialprice\"")).Replace("\"specialprice\"", ""); price = price.Substring(0, price.IndexOf(",")).Replace("$", ""); double specialPrice = 0; double.TryParse(price, out specialPrice); if (specialPrice != 0) sizeProduct.Price = specialPrice.ToString(); else { WriteLogEvent(url, "issue accured in getting price info for variants"); } if (variantCounter != 1) sizeProduct.Isparent = false; Products.Add(sizeProduct); variantCounter++; } else { WriteLogEvent(url, "Stock string not find for color:" + colorOption.label); } } #endregion getAvailability } catch { WriteLogEvent(url, "issue accured in getting stock etc info for variants"); } } else { try { foreach (Option2 sizeOption in option2) { int loopCounter = 1; string[] cominations = attributeCombScript.Split(new string[] { "\"" + sizeOption.id + "\":{" }, StringSplitOptions.None); bool jsonFine = false; try { foreach (string comb in cominations) { filterString = comb; if (filterString.Length > 13) { if (loopCounter == 1 && filterString.Contains("=")) { } else if (!filterString.Substring(0, 13).Contains("availability") && filterString.Contains("availability")) { jsonFine = true; break; } } loopCounter++; } } catch { } if (jsonFine) { foreach (Option2 colorOption in option1) { bool isStockStringExist = true; string filterString1 = ""; try { filterString1 = filterString.Substring(filterString.IndexOf("\"" + colorOption.id + "\":{")).ToLower(); } catch { isStockStringExist = false; } if (isStockStringExist) { BusinessLayer.Product sizeProduct = new BusinessLayer.Product(); sizeProduct = (BusinessLayer.Product)product.Clone(); sizeProduct.parentsku = sku + "-parent"; sizeProduct.SKU = sku + "-" + sizeOption.id + "-" + colorOption.id; sizeProduct.Color = colorOption.label; sizeProduct.Size = sizeOption.label; #region getAvailability stock = filterString1.Substring(filterString1.IndexOf("\"availability\"")).Replace("\"availability\"", ""); stock = stock.Substring(0, stock.IndexOf(",")); saleInfo = filterString1.Substring(filterString1.IndexOf("\"saleinfo\"")).Replace("\"saleinfo\"", ""); saleInfo = saleInfo.Substring(0, saleInfo.IndexOf(",")); if (stock.Contains("normal") && saleInfo.Contains("in stock")) sizeProduct.Stock = "1"; else sizeProduct.Stock = "0"; price = filterString1.Substring(filterString1.IndexOf("\"specialprice\"")).Replace("\"specialprice\"", ""); price = price.Substring(0, price.IndexOf(",")).Replace("$", "").Replace(":", "").Replace("\"", ""); double specialPrice = 0; double.TryParse(price, out specialPrice); if (specialPrice != 0) sizeProduct.Price = specialPrice.ToString(); else { WriteLogEvent(url, "issue accured in getting price info for variants"); } if (variantCounter != 1) sizeProduct.Isparent = false; Products.Add(sizeProduct); variantCounter++; } else { WriteLogEvent(url, "Stock string not find for color:" + colorOption.label); } #endregion getAvailability } } else WriteLogEvent(url, "Not find size option in json in order to find options stocks, size option label " + sizeOption.label + " size option id " + sizeOption.id); } } catch { WriteLogEvent(url, "issue accured in getting stock etc info for variants"); } } } else WriteLogEvent(url, "there is no any size and color in deserialize script. Please check this on urgent basis."); } catch (Exception exp) { WriteLogEvent(url, "Issue accured in deserialize script, due to which this product had not sync to db."); } } #endregion Variation } catch (Exception exp) { WriteLogEvent(url, "Issue accured in reading product info from given product url. exp: " + exp.Message); } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title if (_doc.DocumentNode.SelectNodes("//h1[@class=\"productDescLarge\"]") != null) { product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//h1[@class=\"productDescLarge\"]")[0].InnerText.Trim()); } else { WriteLogEvent(url, "title not found"); } #endregion title #region price if (_doc.DocumentNode.SelectNodes("//span[@class=\"productPriceLarge\"]") != null) { product.Price = _doc.DocumentNode.SelectNodes("//span[@class=\"productPriceLarge\"]")[0].InnerText.Replace("$", "").Trim(); } else { product.Price = "0"; WriteLogEvent(url, "Price not found"); } #endregion price #region Brand try { if (product.Name.Length > 0) { product.Brand = product.Name.Substring(0, product.Name.IndexOf(' ')); product.Manufacturer = product.Name.Substring(0, product.Name.IndexOf(' ')); product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } else { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } } catch { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } #endregion Brand #region Category if (_doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_lnkMoreCatetory\"]") != null) { try { string Category = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_lnkMoreCatetory\"]")[0].InnerText); if (Category.Contains("->")) { Category = Category.Split(new string[] { "->" }, StringSplitOptions.RemoveEmptyEntries)[0]; } product.Category = "FDCA" + Category.Trim(); } catch { WriteLogEvent(url, "Category not found"); } } else { WriteLogEvent(url, "Category not found"); } #endregion Category product.Currency = "CAD"; #region description string Description = ""; var allElementsWithClassFloat = _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblSpecification\"]"); if (allElementsWithClassFloat != null) { foreach (HtmlNode node in allElementsWithClassFloat) { Description = Description + " " + node.InnerText.Trim(); } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); try { if (Description.Length > 2000) { Description = Description.Substring(0, 1997) + "..."; } } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")).Replace("factorydirect.ca", ""); } else { WriteLogEvent(url, "Description not found"); } #endregion description #region BulletPoints string Feature = ""; string Bullets = ""; HtmlNodeCollection collection = _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblSpecification\"]"); if (collection != null) { int PointCounter = 1; foreach (HtmlNode node in collection) { try { Feature = node.InnerText; if (Feature.Length > 480) { Feature = Feature.Substring(0, 480); } if (Bullets.Length + Feature.Length + 2 <= PointCounter * 480) { Bullets = Bullets + Feature + ". "; } else { Bullets = Bullets + "@@" + Feature + ". "; PointCounter++; } } catch { } } if (!string.IsNullOrEmpty(Bullets)) { Bullets = Bullets.Trim().Replace("factorydirect.ca", ""); } } else { WriteLogEvent(url, "BulletPoints not found"); } if (Bullets.Length > 0) { Bullets = Removeunsuaalcharcterfromstring(StripHTML(Bullets).Trim()); string[] BulletPoints = Bullets.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < BulletPoints.Length; i++) { if (i == 0) { product.Bulletpoints1 = BulletPoints[i].ToString(); } if (i == 1) { product.Bulletpoints2 = BulletPoints[i].ToString(); } if (i == 2) { product.Bulletpoints3 = BulletPoints[i].ToString(); } if (i == 3) { product.Bulletpoints4 = BulletPoints[i].ToString(); } if (i == 4) { product.Bulletpoints5 = BulletPoints[i].ToString(); } } } if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) { product.Bulletpoints1 = product.Name; } } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) { product.Bulletpoints1 = product.Description.Substring(0, 497); } else { product.Bulletpoints1 = product.Description; } } #endregion BulletPoints #region Image string Images = ""; if (_doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_ProductImageHyperLink\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//a[@id=\"ctl00_MainBodyContent_ProductImageHyperLink\"]")[0].Attributes) { if (attr.Name == "href") { Images = attr.Value.Trim(); } } } else if (_doc.DocumentNode.SelectNodes("//img[@id=\"ctl00_MainBodyContent_imgProduct\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//img[@id=\"ctl00_MainBodyContent_imgProduct\"]")[0].Attributes) { if (attr.Name == "src") { Images = attr.Value.Trim(); } } } else { WriteLogEvent(url, "Main Images not found"); } product.Image = Images; #endregion Image #region sku if (_doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblProductCode\"]") != null) { product.SKU = "FDCA" + _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblProductCode\"]")[0].InnerText.Trim(); product.parentsku = "FDCA" + _doc.DocumentNode.SelectNodes("//span[@id=\"ctl00_MainBodyContent_lblProductCode\"]")[0].InnerText.Trim(); } #endregion sku product.Isparent = true; product.Stock = "0"; if (_doc.DocumentNode.SelectNodes("//input[@id=\"ctl00_MainBodyContent_btnAdd\"]") != null) { product.Stock = "1"; } product.URL = url; if (product.Brand.ToUpper() != "SOLOGEAR") { Products.Add(product); } } catch { } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { BusinessLayer.Product product = new BusinessLayer.Product(); try { string Bullets = ""; #region title HtmlNodeCollection formColl = _doc.DocumentNode.SelectNodes("//div[@class=\"item_title\"]/h1"); if (formColl != null) product.Name = System.Net.WebUtility.HtmlDecode(formColl[0].InnerText).Trim(); else if (_doc.DocumentNode.SelectNodes("//title") != null) product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//title")[0].InnerText).Trim(); else _writer.WriteLine(url + " " + "title not found"); #endregion title #region Price string priceString = ""; double Price = 0; if (_doc.DocumentNode.SelectNodes("//span[@id=\"SalePrice\"]") != null) { priceString = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@id=\"SalePrice\"]")[0].InnerText).Replace("$", "").Trim(); double.TryParse(priceString, out Price); if (Price != 0) product.Price = Price.ToString(); //System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).re; else _writer.WriteLine(url + " " + "Price not found"); } else _writer.WriteLine(url + " " + "Price not found"); #endregion Price #region Brand try { if (_doc.DocumentNode.SelectNodes("//span[@class=\"icon\"]/img") != null) { if (_doc.DocumentNode.SelectNodes("//span[@class=\"icon\"]/img")[0].Attributes["src"].Value.ToLower().Contains("logos")) { product.Brand = _doc.DocumentNode.SelectNodes("//span[@class=\"icon\"]/img")[0].Attributes["src"].Value.Replace("logos", "").Replace("/", "").Replace(".gif", "").Replace(".png", "").Replace(".jpg", "").Trim(); product.Manufacturer = _doc.DocumentNode.SelectNodes("//span[@class=\"icon\"]/img")[0].Attributes["src"].Value.Replace("logos", "").Replace("/", "").Replace(".gif", "").Replace(".png", "").Replace(".jpg", "").Trim(); } } } catch { } if (string.IsNullOrEmpty(product.Brand)) { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } #endregion Brand #region Category product.Category = string.IsNullOrEmpty(Category) ? "CANCOMJZ HOLDINGS" : Category; #endregion Category product.Currency = "CAD"; int descIndex = 0; int specIndex = 0; int stockIndex = 0; #region description string Description = ""; #region Get Description,stock abnd SpecificationIndex HtmlNodeCollection index = _doc.DocumentNode.SelectNodes("//ul[@class=\"TabbedPanelsTabGroup\"]/li"); if (index != null) { int counter = 0; foreach (HtmlNode node in index) { if (node.InnerText.Trim().ToLower().Trim() == "stock level") stockIndex = counter; else if (node.InnerText.Trim().ToLower().Trim() == "overview") descIndex = counter; else if (node.InnerText.Trim().ToLower().Trim() == "specifications") specIndex = counter; counter++; } } #endregion Get Description,stock abnd SpecificationIndex HtmlNodeCollection desCollection = _doc.DocumentNode.SelectNodes("//div[@class=\"TabbedPanelsContentGroup\"]/div"); if (descIndex != 0) { if (desCollection != null) { try { foreach (HtmlNode node in desCollection[descIndex].ChildNodes) { if (node.Name != "script") { Description = Description + node.InnerHtml; } } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } catch { _writer.WriteLine(url + " " + "Description not found"); } } else _writer.WriteLine(url + " " + "Description not found"); } else _writer.WriteLine(url + " " + "Description not found"); #endregion description #region BulletPoints string Feature = ""; if (specIndex != 0) { if (desCollection != null) { string Header = ""; string Value = ""; int PointCounter = 1; try { if (desCollection[specIndex].SelectNodes(".//td[@class=\"specification\"]") != null) { foreach (HtmlNode node in desCollection[specIndex].SelectNodes(".//td[@class=\"specification\"]")) { try { Header = System.Net.WebUtility.HtmlDecode(node.InnerText.Trim()); Value = System.Net.WebUtility.HtmlDecode(node.NextSibling.InnerText.Trim()); if (Value != "" && Header.Length < 100 && !Header.ToLower().Contains("warranty") && !Header.ToLower().Contains("return")) { Feature = " " + Header + " " + Value; if (Feature.Length > 480) Feature = Feature.Substring(0, 480); if (Bullets.Length + Feature.Length + 2 <= PointCounter * 480) Bullets = Bullets + Feature + ". "; else { Bullets = Bullets + "@@" + Feature + ". "; PointCounter++; } if (Header.ToLower() == "brand") { product.Brand = Value; product.Manufacturer = Value; } } } catch { } } } else { Bullets = Removeunsuaalcharcterfromstring(StripHTML(desCollection[specIndex].InnerText).Trim()); if (Bullets.Length > 1000) Bullets = Bullets.Substring(0, 990) + "..."; } } catch { } if (!string.IsNullOrEmpty(Bullets)) Bullets = Bullets.Trim(); } else _writer.WriteLine(url + " " + "Bullet Points not found"); } else _writer.WriteLine(url + " " + "Bullet Points not found"); if (Bullets.Length > 0) { Bullets = Removeunsuaalcharcterfromstring(StripHTML(Bullets).Trim()); string[] BulletPoints = Bullets.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < BulletPoints.Length; i++) { if (i == 0) product.Bulletpoints1 = BulletPoints[i].ToString(); if (i == 1) product.Bulletpoints2 = BulletPoints[i].ToString(); if (i == 2) product.Bulletpoints3 = BulletPoints[i].ToString(); if (i == 3) product.Bulletpoints4 = BulletPoints[i].ToString(); if (i == 4) product.Bulletpoints5 = BulletPoints[i].ToString(); if (i > 4) break; } } if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; HtmlNodeCollection imgCollection = _doc.DocumentNode.SelectNodes("//div[@class=\"prod_thumb\"]"); if (imgCollection != null) { if (imgCollection[0].SelectNodes(".//img") != null) { foreach (HtmlNode node in imgCollection[0].SelectNodes(".//img")) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "src") { try { if (!node.Attributes["title"].Value.Trim().ToLower().Contains("image not available")) Images = Images + attr.Value.Trim().Replace("40x40", "450x450") + ","; } catch { Images = Images + attr.Value.Trim().Replace("40x40", "450x450") + ","; } break; } } } } } else _writer.WriteLine(url + " " + "Main Images not found"); if (string.IsNullOrEmpty(Images)) { HtmlNodeCollection imgCollection1 = _doc.DocumentNode.SelectNodes("//div[@class=\"preview_img\"]/img"); if (imgCollection != null) { try { if (!imgCollection1[0].Attributes["title"].Value.Trim().ToLower().Contains("image not available")) Images = imgCollection1[0].Attributes["src"].Value.Trim(); } catch { Images = imgCollection1[0].Attributes["src"].Value.Trim(); } } } if (Images.Length > 0) { if (Images.Contains(",")) Images = Images.Substring(0, Images.Length - 1); } product.Image = Images; #endregion Image product.Isparent = true; #region sku string sku = ""; if (_doc.DocumentNode.SelectNodes("//span[@class=\"itdetail\"]/strong") != null) { try { foreach (HtmlNode Node in _doc.DocumentNode.SelectNodes("//span[@class=\"itdetail\"]/strong")) { if (Node.InnerText.ToLower().Contains("part number:")) product.ManPartNO = Removeunsuaalcharcterfromstring(StripHTML(Node.NextSibling.InnerText)).Replace("|", "").Trim(); else if (Node.InnerText.ToLower().Contains("item code:")) { // product.SKU = // product.parentsku = string.IsNullOrEmpty(Removeunsuaalcharcterfromstring(StripHTML(Node.NextSibling.InnerText))) ? "" : "CANCOM" + Removeunsuaalcharcterfromstring(StripHTML(Node.NextSibling.InnerText)).Replace("|", "").Trim(); } } } catch { } } else _writer.WriteLine(url + " " + "Model not found"); if (_doc.DocumentNode.SelectNodes("//input[@name=\"item_id\"]") != null) { product.SKU = string.IsNullOrEmpty(Removeunsuaalcharcterfromstring(StripHTML(_doc.DocumentNode.SelectNodes("//input[@name=\"item_id\"]")[0].Attributes["value"].Value))) ? "" : "CANCOM" + Removeunsuaalcharcterfromstring(StripHTML(_doc.DocumentNode.SelectNodes("//input[@name=\"item_id\"]")[0].Attributes["value"].Value)).Replace("|", "").Trim(); product.parentsku = string.IsNullOrEmpty(Removeunsuaalcharcterfromstring(StripHTML(_doc.DocumentNode.SelectNodes("//input[@name=\"item_id\"]")[0].Attributes["value"].Value))) ? "" : "CANCOM" + Removeunsuaalcharcterfromstring(StripHTML(_doc.DocumentNode.SelectNodes("//input[@name=\"item_id\"]")[0].Attributes["value"].Value)).Replace("|", "").Trim(); } else _writer.WriteLine(url + " " + "Sku not found"); #endregion sku #region stock product.Stock = "0"; int Stock = 0; if (desCollection != null) { string Header = ""; string Value = ""; int PointCounter = 1; try { HtmlNodeCollection stockNodes = desCollection[stockIndex].SelectNodes(".//td"); if (stockNodes != null) { for (int i = 0; i < stockNodes.Nodes().Count(); i++) { if (stockNodes[i].InnerText.ToLower().Trim() == "online store") { int.TryParse(stockNodes[i + 1].InnerText.Trim(), out Stock); break; } } } } catch { Stock = 2; } } product.Stock = Stock > 1 ? "1" : "0"; #endregion stock product.URL = url; if (!string.IsNullOrEmpty(product.Image)) if (!product.Image.ToLower().Contains("ina.jpg")) Products.Add(product); } catch (Exception exp) { _writer.WriteLine(url + " " + "Issue accured in reading product info from given product url. exp: " + exp.Message); } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { if (_doc.DocumentNode.SelectNodes("//table[@class=\"ProdTable\"]") != null) { foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//table[@class=\"ProdTable\"]")) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title if (node.SelectNodes(".//span[@class=\"styProductName\"]") != null) product.Name = System.Net.WebUtility.HtmlDecode(node.SelectNodes(".//span[@class=\"styProductName\"]")[0].InnerText.Trim()); else WriteLogEvent(url, "title not found"); #endregion title #region price if (node.SelectNodes(".//span[@class=\"styPriceVal\"]") != null) product.Price = node.SelectNodes(".//span[@class=\"styPriceVal\"]")[0].InnerText.Replace("$", "").Trim(); else { product.Price = "0"; WriteLogEvent(url, "Price not found"); } #endregion price #region Brand product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; #endregion Brand #region Category product.Category = Category; #endregion Category product.Currency = "CAD"; #region description string Description = ""; string BulletPoint1 = ""; try { if (node.SelectNodes(".//span[@class=\"styProductDescShort\"]") != null) { foreach (HtmlNode node1 in node.SelectNodes(".//span[@class=\"styProductDescShort\"]")) { if (node1.PreviousSibling.Name == "b") { Description = Description + node1.PreviousSibling.InnerText + " " + node1.InnerText + " "; } } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); BulletPoint1 = Description; try { if (BulletPoint1.Length > 500) BulletPoint1 = BulletPoint1.Substring(0, 496) + "..."; if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } } else { WriteLogEvent(url, "Description not found"); Description = product.Name; BulletPoint1 = product.Name; } } catch { Description = product.Name; BulletPoint1 = product.Name; } product.Description = Description; product.Bulletpoints1 = BulletPoint1; #endregion description #region Image if (node.SelectNodes(".//img") != null) { string ImageUrl = ""; string alt = ""; foreach (HtmlNode node1 in node.SelectNodes(".//td[@class=\"prodImage\"]")) { if (node1.SelectNodes(".//img") != null) { foreach (HtmlNode node2 in node.SelectNodes(".//img")) { foreach (HtmlAttribute attr in node2.Attributes) { if (attr.Name == "src") ImageUrl = attr.Value.Trim(); else if (attr.Name == "alt") alt = attr.Value.Trim(); } if (!string.IsNullOrEmpty(alt)) { product.Image = _ScrapeUrl + "/" + ImageUrl; break; } } } } } else WriteLogEvent(url, "Main Images not found"); #endregion Image #region sku if (node.SelectNodes(".//span[@class=\"styProductCodeVal\"]") != null) { product.SKU = "BBALCA" + node.SelectNodes(".//span[@class=\"styProductCodeVal\"]")[0].InnerText.Trim(); product.parentsku = "BBALCA" + node.SelectNodes(".//span[@class=\"styProductCodeVal\"]")[0].InnerText.Trim(); } #endregion sku product.Isparent = true; product.Stock = "0"; if (node.SelectNodes(".//td[@class=\"bg\"]") != null) { foreach (HtmlNode node1 in node.SelectNodes(".//td[@class=\"bg\"]")[0].SelectNodes(".//b")) { if (node1.InnerText.Trim().ToLower().Contains("quantity in stock:")) { string quantityText = node1.InnerText.Trim().ToLower().Replace("quantity in stock:", ""); int quantity = 0; int.TryParse(quantityText, out quantity); product.Stock = quantity.ToString(); } else WriteLogEvent(url, "quantity in stock: is not exist in quantity node"); } } var count = (from prd in Products where prd.SKU == product.SKU select prd).FirstOrDefault(); if (count == null) { product.URL = url; //double priceCheck = 0; //double minimumPrice = 1.5; //double.TryParse(product.Price, out priceCheck); //if (priceCheck > minimumPrice) Products.Add(product); } } catch { } } } else WriteLogEvent(url, "App failed to read product on given url"); }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { BusinessLayer.Product product = new BusinessLayer.Product(); try { string Bullets = ""; #region title HtmlNodeCollection formColl = _doc.DocumentNode.SelectNodes("//div[@class=\"prodName\"]/h1"); if (formColl != null) product.Name = System.Net.WebUtility.HtmlDecode(formColl[0].InnerText).Trim(); else if (_doc.DocumentNode.SelectNodes("//meta[@property=\"og:title\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//meta[@property=\"og:title\"]")[0].Attributes) { if (attr.Name == "content") { product.Name = System.Net.WebUtility.HtmlDecode(attr.Value).Trim(); break; } } } else _writer.WriteLine(url + " " + "title not found"); #endregion title #region Price string priceString = ""; double Price = 0; if (_doc.DocumentNode.SelectNodes("//span[@class=\"salePrice\"]") != null) { priceString = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"salePrice\"]")[0].InnerText).Replace("$", "").Trim(); double.TryParse(priceString, out Price); if (Price != 0) product.Price = Price.ToString(); //System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).re; else _writer.WriteLine(url + " " + "Price not found"); } else if (_doc.DocumentNode.SelectNodes("//meta[@itemprop=\"price\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//meta[@itemprop=\"price\"]")[0].Attributes) { if (attr.Name == "content") { priceString = System.Net.WebUtility.HtmlDecode(attr.Value).Replace("$", "").Trim(); break; } } double.TryParse(priceString, out Price); if (Price != 0) product.Price = Price.ToString(); //System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).re; else _writer.WriteLine(url + " " + "Price not found"); } else _writer.WriteLine(url + " " + "Price not found"); #endregion Price #region Brand if (_doc.DocumentNode.SelectNodes("//div[@itemprop=\"brand\"]/meta") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//div[@itemprop=\"brand\"]/meta")[0].Attributes) { if (attr.Name == "content") { product.Brand = attr.Value.Trim(); product.Manufacturer = attr.Value.Trim(); break; } } } else { product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; } #endregion Brand #region Category product.Category = string.IsNullOrEmpty(Category) ? "TGRDRCTJZ HOLDINGS" : Category; #endregion Category product.Currency = "CAD"; #region description string Description = ""; HtmlNodeCollection desCollection = _doc.DocumentNode.SelectNodes("//div[@id=\"prodinfo\"]"); if (desCollection != null) { try { Description = Removeunsuaalcharcterfromstring(StripHTML(desCollection[0].InnerText).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } catch { _writer.WriteLine(url + " " + "Description not found"); } } else _writer.WriteLine(url + " " + "Description not found"); #endregion description #region BulletPoints string Feature = ""; HtmlNodeCollection collection = _doc.DocumentNode.SelectNodes("//table[@class=\"prodSpec\"]"); if (collection != null) { string Header = ""; string Value = ""; int PointCounter = 1; try { foreach (HtmlNode node in collection[0].SelectNodes(".//tr")) { try { Header = System.Net.WebUtility.HtmlDecode(node.SelectNodes(".//th")[0].InnerText.Trim()); if (node.SelectNodes(".//td") != null) { Value = System.Net.WebUtility.HtmlDecode(node.SelectNodes(".//td")[0].InnerText.Trim()); if (Value != "") { Feature = " " + Header + " " + Value; if (Feature.Length > 480) Feature = Feature.Substring(0, 480); if (Bullets.Length + Feature.Length + 2 <= PointCounter * 480) Bullets = Bullets + Feature + ". "; else { Bullets = Bullets + "@@" + Feature + ". "; PointCounter++; } } } } catch { } } } catch { } if (!string.IsNullOrEmpty(Bullets)) Bullets = Bullets.Trim(); } else _writer.WriteLine(url + " " + "Bullet Points not found"); if (Bullets.Length > 0) { Bullets = Removeunsuaalcharcterfromstring(StripHTML(Bullets).Trim()); string[] BulletPoints = Bullets.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < BulletPoints.Length; i++) { if (i == 0) product.Bulletpoints1 = BulletPoints[i].ToString(); if (i == 1) product.Bulletpoints2 = BulletPoints[i].ToString(); if (i == 2) product.Bulletpoints3 = BulletPoints[i].ToString(); if (i == 3) product.Bulletpoints4 = BulletPoints[i].ToString(); if (i == 4) product.Bulletpoints5 = BulletPoints[i].ToString(); if (i > 4) break; } } if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; if (_doc.DocumentNode.SelectNodes("//meta[@itemprop=\"image\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//meta[@itemprop=\"image\"]")[0].Attributes) { if (attr.Name == "content") { Images = attr.Value.Trim() + ","; break; } } } HtmlNodeCollection imgCollection = _doc.DocumentNode.SelectNodes("//ul[@id=\"viewsImg\"]"); if (imgCollection != null) { foreach (HtmlNode node in imgCollection[0].SelectNodes(".//img")) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "src") { Images = Images + attr.Value.Trim().Replace("/small", "/large") + ","; break; } } } } else _writer.WriteLine(url + " " + "Main Images not found"); if (Images.Length > 0) Images = Images.Substring(0, Images.Length - 1); product.Image = Images; #endregion Image product.Isparent = true; #region sku string sku = ""; if (_doc.DocumentNode.SelectNodes("//span[@class=\"sku\"]/strong") != null) { try { foreach (HtmlNode Node in _doc.DocumentNode.SelectNodes("//span[@class=\"sku\"]/strong")) { if (Node.InnerText.ToLower().Contains("model#")) product.ManPartNO = Removeunsuaalcharcterfromstring(StripHTML(Node.NextSibling.InnerText)).Replace("|", "").Trim(); else if (Node.InnerText.ToLower().Contains("item#")) { product.SKU = "TGRDRCT" + Removeunsuaalcharcterfromstring(StripHTML(Node.NextSibling.InnerText)).Replace("|", "").Trim(); product.parentsku = "TGRDRCT" + Removeunsuaalcharcterfromstring(StripHTML(Node.NextSibling.InnerText)).Replace("|", "").Trim(); } } } catch { } } else _writer.WriteLine(url + " " + "Model and SKU not found"); //if (_doc.DocumentNode.SelectNodes("//meta[@itemprop=\"sku\"]") != null) //{ // foreach (HtmlAttribute node in _doc.DocumentNode.SelectNodes("//meta[@itemprop=\"sku\"]")[0].Attributes) // { // if (node.Name == "content") // { // product.SKU = "TGRDRCT" + node.Value.Trim(); // product.parentsku = "TGRDRCT" + node.Value.Trim(); // } // } //} //else // _writer.WriteLine(url + " " + "sku not found"); #endregion sku //#region upc //if (_doc.DocumentNode.SelectNodes("//meta[@itemprop=\"gtin14\"]") != null) //{ // foreach (HtmlAttribute node in _doc.DocumentNode.SelectNodes("//meta[@itemprop=\"gtin14\"]")[0].Attributes) // { // if (node.Name == "content") // { // product.UPC = node.Value.Trim(); // if(product.UPC=="00000000000000") // product.UPC=""; // break; // } // } //} //else // _writer.WriteLine(url + " " + "upc not found"); //#endregion upc #region stock product.Stock = "0"; if (_doc.DocumentNode.SelectNodes("//meta[@itemprop=\"availability\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//meta[@itemprop=\"availability\"]")[0].Attributes) { if (attr.Name == "content") { if (attr.Value.ToLower() == "instock") { product.Stock = "1"; break; } } } } #endregion stock product.URL = url; if (!string.IsNullOrEmpty(product.UPC)) product.ISGtin = true; else product.ISGtin = false; Products.Add(product); } catch (Exception exp) { _writer.WriteLine(url + " " + "Issue accured in reading product info from given product url. exp: " + exp.Message); } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title price HtmlNodeCollection formColl = _doc.DocumentNode.SelectNodes("//div[@id=\"bodyContent\"]"); if (formColl != null) { if (formColl[0].SelectNodes(".//h1") != null) { int Counter = 0; foreach (HtmlNode node in formColl[0].SelectNodes(".//h1")) { if (Counter == 0) { decimal Price = 0; decimal.TryParse(node.InnerText.ToLower().Replace("$", "").Replace("ca", "").Trim(), out Price); product.Price = Price.ToString(); if (Price == 0) { product.Price = "0"; WriteLogEvent(url, "Price not found"); } } else product.Name = System.Net.WebUtility.HtmlDecode(node.InnerText.Trim()); Counter++; if (product.Price == "0") break; } } else WriteLogEvent(url, "title not found"); #endregion title price #region Brand product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; #endregion Brand #region Category product.Category = Category; #endregion Category product.Currency = "CAD"; #region description string Description = ""; HtmlNodeCollection desCollection = _doc.DocumentNode.SelectNodes("//div[@class=\"contentText\"]"); if (desCollection != null) { foreach (HtmlNode node in desCollection[0].ChildNodes) { if (!node.InnerText.ToLower().Contains("wholesale") && !node.InnerText.ToLower().Contains("$") && !node.InnerText.ToLower().Contains("http")) Description = Description + Removeunsuaalcharcterfromstring(StripHTML(node.InnerText).Trim() + " "); } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()).Replace("httpwww.partysavvy.co.uk", "").Replace("httpwww.openparty.com", ""); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } else WriteLogEvent(url, "Description not found"); #endregion description #region BulletPoints if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; HtmlNodeCollection imgCollection = _doc.DocumentNode.SelectNodes("//div[@id=\"piGal\"]"); if (imgCollection != null) { HtmlNodeCollection imgCollection1 = imgCollection[0].SelectNodes(".//a"); foreach (HtmlNode node in imgCollection1) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "href") Images = Images + attr.Value.Trim() + ","; } break; } } else WriteLogEvent(url, "Main Images not found"); if (Images.Length > 0) Images = Images.Substring(0, Images.Length - 1); product.Image = Images; #endregion Image product.Isparent = true; #region sku if (_doc.DocumentNode.SelectNodes("//input[@name=\"products_id\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//input[@name=\"products_id\"]")[0].Attributes) { if (attr.Name == "value") { product.SKU = "OPAR" + attr.Value.Trim(); product.parentsku = "OPAR" + attr.Value.Trim(); } } } else WriteLogEvent(url, "SKU not found"); #endregion sku #region stock product.Stock = "1"; #endregion stock product.URL = url; Products.Add(product); } else WriteLogEvent(url, "Issue accured in reading product info from given product url. exp: "); } catch (Exception exp) { WriteLogEvent(url, "Issue accured in reading product info from given product url. exp: " + exp.Message); } }
public void work_RunWorkerAsync(object sender, RunWorkerCompletedEventArgs e) { #region 401games if (_IS401games) { if (_IsProduct && !Erorr_401_1) { int index = 0; index = gridindex; gridindex++; try { BusinessLayer.Product Product = new BusinessLayer.Product(); Product.URL = Url1; Product.Isparent = true; #region title HtmlNodeCollection _Title = _Work1doc.DocumentNode.SelectNodes("//h1[@class=\"title product\"]"); if (_Title != null) Product.Name = System.Net.WebUtility.HtmlDecode(CommanFunction.Removeunsuaalcharcterfromstring(_Title[0].InnerText.Trim())).Replace(">", "").Replace("<", ""); else { HtmlNodeCollection _Title1 = _Work1doc.DocumentNode.SelectNodes("//h1"); if (_Title1 != null) Product.Name = System.Net.WebUtility.HtmlDecode(CommanFunction.Removeunsuaalcharcterfromstring(_Title1[0].InnerText.Trim())).Replace(">", "").Replace("<", ""); } #endregion title #region description _Description1 = ""; HtmlNodeCollection _description = _Work1doc.DocumentNode.SelectNodes("//div[@id=\"tab_desc\"]"); if (_description != null) { _Description1 = CommanFunction.Removeunsuaalcharcterfromstring(CommanFunction.StripHTML(_description[0].InnerHtml.Replace("Product Description", "")).Trim()); } else { HtmlNodeCollection _description1 = _Work1doc.DocumentNode.SelectNodes("//div[@class=\"ldesc\"]"); if (_description != null) { _Description1 = CommanFunction.Removeunsuaalcharcterfromstring(CommanFunction.StripHTML(_description1[0].InnerHtml).Trim()); } } try { if (_Description1.Length > 2000) _Description1 = _Description1.Substring(0, 1997) + "..."; } catch { } Product.Description = System.Net.WebUtility.HtmlDecode(_Description1.Replace("Â", "").Replace(">", "").Replace("<", "")); #endregion description #region manufacturer Product.Manufacturer = BrandName1; Product.Brand = BrandName1; #endregion manufacturer #region For decsription empty try { if (String.IsNullOrEmpty(Product.Description)) { Product.Description = Product.Name.ToString().Replace(">", "").Replace("<", ""); Product.Bulletpoints1 = Product.Name.ToString().Replace(">", "").Replace("<", ""); } else { if (Product.Description.Length > 500) Product.Bulletpoints1 = Product.Description.Substring(0, 497); else Product.Bulletpoints1 = Product.Description; } } catch { } #endregion For decsription empty #region currency Product.Currency = "CDN"; #endregion currency #region price,stock if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability \"]/span") != null) { if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability \"]/span")[0].InnerText.Trim() == "0") { Product.Stock = "0"; } else { Product.Stock = _Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability \"]/span")[0].InnerText.ToLower().Replace("in-stock :", "").Trim(); } } else if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability\"]/span") != null) { if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability\"]/span")[0].InnerText.Trim() == "0") { Product.Stock = "0"; } else { Product.Stock = _Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability\"]/span")[0].InnerText.ToLower().Replace("in-stock :", "").Trim(); } } else if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability in-stock\"]") != null) { if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability in-stock\"]")[0].InnerText.ToLower().Replace("Quantity :", "").Trim() == "0") { Product.Stock = "0"; } else { Product.Stock = _Work1doc.DocumentNode.SelectNodes("//div[@class=\"availability in-stock\"]")[0].InnerText.ToLower().Replace("Quantity :", "").Replace("in-stock :", "").Trim(); } } try { if ((Convert.ToInt32(Product.Stock) > 30) || String.IsNullOrEmpty(Product.Stock)) { Product.Stock = "30"; } } catch { } HtmlNode _Node = _Work1doc.DocumentNode.SelectNodes("//div[@id=\"prices\"]")[0]; if (_Node != null) { if (_Node.SelectNodes(".//div[@class=\"discounted-price\"]") != null) { Product.Price = _Node.SelectNodes(".//div[@class=\"discounted-price\"]")[0].InnerText.Replace("\"", "").Replace(",", "").Replace("$", "").Replace("price", "").Replace(":", "").Trim(); } else if (_Node.SelectNodes(".//div[@class=\"regular-price\"]") != null) { Product.Price = _Node.SelectNodes(".//div[@class=\"regular-price\"]")[0].InnerText.Replace("\"", "").Replace(",", "").Replace("$", "").Replace("price", "").Replace(":", "").Trim(); } } #endregion price,stock #region sku try { if (String.IsNullOrEmpty(Product.Price)) { Product.Price = "0"; } if (Convert.ToDecimal(Product.Price) > 0) { Product.SKU = GenrateSkuFromDatbase(CommanFunction.GenerateSku("ST4GAM", CommanFunction.Removeunsuaalcharcterfromstring(Product.Name.Trim())), CommanFunction.Removeunsuaalcharcterfromstring(Product.Name.Trim()), "store.401games", Convert.ToDecimal(Product.Price), Url1); Product.parentsku = Product.SKU; } } catch { Product.SKU = ""; } #endregion sku #region Image if (_Work1doc.DocumentNode.SelectNodes("//img[@id=\"main_image\"]") != null) { foreach (HtmlAttribute _Attribute in _Work1doc.DocumentNode.SelectNodes("//img[@id=\"main_image\"]")[0].Attributes) { if (_Attribute.Name == "src") { Product.Image = "http://store.401games.ca/" + _Attribute.Value; } } } else if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"product-img-wrapper\"]/img") != null) { foreach (HtmlAttribute _Attribute in _Work1doc.DocumentNode.SelectNodes("//div[@class=\"product-img-wrapper\"]/img")[0].Attributes) { if (_Attribute.Name == "src") { Product.Image = "http://store.401games.ca/" + _Attribute.Value; } } } #endregion Image #region category if (_Work1doc.DocumentNode.SelectNodes("//div[@class=\"breadcrumbs\"]//ul//li[@class=\"category_path\"]//a") != null) { Product.Category = "ST4GAM" + _Work1doc.DocumentNode.SelectNodes("//div[@class=\"breadcrumbs\"]//ul//li[@class=\"category_path\"]//a")[0].InnerText.Trim(); } #endregion category #region setQuantityTo0IfLessthen3 if (string.IsNullOrEmpty(Product.Stock)) Product.Stock = "0"; Product.Stock =Convert.ToInt32( Product.Stock) < 3 ? "0 ": (Convert.ToInt32( Product.Stock)-2).ToString(); #endregion setQuantityTo0IfLessthen3 Products.Add(Product); } catch (Exception exp) { _writer.WriteLine("worker issue for product url" + Url1 + " " + exp.Message); } } } #endregion 401games }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title HtmlNodeCollection formColl = _doc.DocumentNode.SelectNodes("//h1[@class=\"mainbox-title\"]"); if (formColl != null) product.Name = System.Net.WebUtility.HtmlDecode(formColl[0].InnerText).Trim(); else if (_doc.DocumentNode.SelectNodes("//h1[@class=\"ty-product-block-title\"]") != null) product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//h1[@class=\"ty-product-block-title\"]")[0].InnerText).Trim(); else WriteLogEvent(url, "title not found"); #endregion title #region Price string priceString = ""; double Price = 0; if (_doc.DocumentNode.SelectNodes("//span[@class=\"ty-price\"]") != null) { priceString = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"ty-price\"]")[0].InnerText).Replace("$", "").Trim(); double.TryParse(priceString, out Price); if (Price != 0) product.Price = Price.ToString(); //System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).re; else WriteLogEvent(url, "Price not found"); } else if (_doc.DocumentNode.SelectNodes("//meta[@itemprop=\"price\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//meta[@itemprop=\"price\"]")[0].Attributes) { if (attr.Name == "content") priceString = System.Net.WebUtility.HtmlDecode(attr.Value).Replace("$", "").Trim(); } double.TryParse(priceString, out Price); if (Price != 0) product.Price = Price.ToString(); //System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//span[@class=\"regular-price\"]/span[@class=\"price\"]")[0].InnerText).re; else WriteLogEvent(url, "Price not found"); } else WriteLogEvent(url, "Price not found"); #endregion Price #region Brand //if (_doc.DocumentNode.SelectNodes("//img[@class=\"brandlogo\"]") != null) //{ // foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//img[@class=\"brandlogo\"]")[0].Attributes) // { // if (attr.Name == "title") // { // product.Brand = attr.Value.Trim(); // product.Manufacturer = attr.Value.Trim(); // } // } //} //else //{ // product.Brand = "JZ HOLDINGS"; // product.Manufacturer = "JZ HOLDINGS"; //} product.Brand = Category; product.Manufacturer = Category; #endregion Brand #region Category HtmlNodeCollection coll = _doc.DocumentNode.SelectNodes("//div[@class=\"breadcrumbs clearfix\"]"); if (coll != null) { HtmlNodeCollection coll1 = coll[0].SelectNodes(".//a"); foreach (HtmlNode node in coll1) { if (node.InnerText.ToLower().Trim() != "home") { product.Category = "POOLSP" + node.InnerText.Trim(); break; } } } else product.Category = "POOLSPJZ HOLDINGS"; #endregion Category product.Currency = "CAD"; #region description string Description = ""; string BulletPoints = ""; HtmlNodeCollection desCollection = _doc.DocumentNode.SelectNodes("//div[@id=\"content_description\"]"); if (desCollection != null) { try { Description = Removeunsuaalcharcterfromstring(StripHTML(desCollection[0].InnerText).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } catch { WriteLogEvent(url, "Description not found"); } } else WriteLogEvent(url, "Description not found"); #endregion description #region BulletPoints if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion BulletPoints #region Image string Images = ""; HtmlNodeCollection divCollection = _doc.DocumentNode.SelectNodes("//div[@class=\"ty-product-img cm-preview-wrapper\"]"); if (divCollection != null) { HtmlNodeCollection imgCollection = divCollection[0].SelectNodes(".//img[@class=\"ty-pict \"]"); if (imgCollection != null) { foreach (HtmlNode node in imgCollection) { foreach (HtmlAttribute attr in node.Attributes) { if (attr.Name == "src") Images = Images + attr.Value.Trim() + ","; } } } } else WriteLogEvent(url, "Main Images not found"); if (Images.Length > 0) Images = Images.Substring(0, Images.Length - 1); product.Image = Images; #endregion Image product.Isparent = true; #region sku string sku = ""; if (_doc.DocumentNode.SelectNodes("//span[@class=\"ty-control-group__item\"]") != null) { product.SKU = "POOLSP" + _doc.DocumentNode.SelectNodes("//span[@class=\"ty-control-group__item\"]")[0].InnerText.Trim(); product.parentsku = "POOLSP" + _doc.DocumentNode.SelectNodes("//span[@class=\"ty-control-group__item\"]")[0].InnerText.Trim(); } else WriteLogEvent(url, "SKU not found"); #endregion sku #region stock product.Stock = "0"; if (_doc.DocumentNode.SelectNodes("//span[@class=\"ty-qty-in-stock ty-control-group__item\"]") != null) { if (_doc.DocumentNode.SelectNodes("//span[@class=\"ty-qty-in-stock ty-control-group__item\"]")[0].InnerText.ToLower() == "in stock") product.Stock = "1"; } #endregion stock product.URL = url; if (!_doc.DocumentNode.InnerHtml.ToLower().Contains("weeks")) Products.Add(product); } catch (Exception exp) { WriteLogEvent(url, "Issue accured in reading product info from given product url. exp: " + exp.Message); } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url, string Category) { if (_doc.DocumentNode.SelectNodes("//table[@class=\"ProdTable\"]") != null) { foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//table[@class=\"ProdTable\"]")) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title if (node.SelectNodes(".//span[@class=\"styProductName\"]") != null) { product.Name = System.Net.WebUtility.HtmlDecode(node.SelectNodes(".//span[@class=\"styProductName\"]")[0].InnerText.Trim()); } else { WriteLogEvent(url, "title not found"); } #endregion title #region price if (node.SelectNodes(".//span[@class=\"styPriceVal\"]") != null) { product.Price = node.SelectNodes(".//span[@class=\"styPriceVal\"]")[0].InnerText.Replace("$", "").Trim(); } else { product.Price = "0"; WriteLogEvent(url, "Price not found"); } #endregion price #region Brand product.Brand = "JZ HOLDINGS"; product.Manufacturer = "JZ HOLDINGS"; #endregion Brand #region Category product.Category = Category; #endregion Category product.Currency = "CAD"; #region description string Description = ""; string BulletPoint1 = ""; try { if (node.SelectNodes(".//span[@class=\"styProductDescShort\"]") != null) { foreach (HtmlNode node1 in node.SelectNodes(".//span[@class=\"styProductDescShort\"]")) { if (node1.PreviousSibling.Name == "b") { Description = Description + node1.PreviousSibling.InnerText + " " + node1.InnerText + " "; } } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); BulletPoint1 = Description; try { if (BulletPoint1.Length > 500) { BulletPoint1 = BulletPoint1.Substring(0, 496) + "..."; } if (Description.Length > 2000) { Description = Description.Substring(0, 1997) + "..."; } } catch { } } else { WriteLogEvent(url, "Description not found"); Description = product.Name; BulletPoint1 = product.Name; } } catch { Description = product.Name; BulletPoint1 = product.Name; } product.Description = Description; product.Bulletpoints1 = BulletPoint1; #endregion description #region Image if (node.SelectNodes(".//img") != null) { string ImageUrl = ""; string alt = ""; foreach (HtmlNode node1 in node.SelectNodes(".//td[@class=\"prodImage\"]")) { if (node1.SelectNodes(".//img") != null) { foreach (HtmlNode node2 in node.SelectNodes(".//img")) { foreach (HtmlAttribute attr in node2.Attributes) { if (attr.Name == "src") { ImageUrl = attr.Value.Trim(); } else if (attr.Name == "alt") { alt = attr.Value.Trim(); } } if (!string.IsNullOrEmpty(alt)) { product.Image = _ScrapeUrl + "/" + ImageUrl; break; } } } } } else { WriteLogEvent(url, "Main Images not found"); } #endregion Image #region sku if (node.SelectNodes(".//span[@class=\"styProductCodeVal\"]") != null) { product.SKU = "BBALCA" + node.SelectNodes(".//span[@class=\"styProductCodeVal\"]")[0].InnerText.Trim(); product.parentsku = "BBALCA" + node.SelectNodes(".//span[@class=\"styProductCodeVal\"]")[0].InnerText.Trim(); } #endregion sku product.Isparent = true; product.Stock = "0"; if (node.SelectNodes(".//td[@class=\"bg\"]") != null) { foreach (HtmlNode node1 in node.SelectNodes(".//td[@class=\"bg\"]")[0].SelectNodes(".//b")) { if (node1.InnerText.Trim().ToLower().Contains("quantity in stock:")) { string quantityText = node1.InnerText.Trim().ToLower().Replace("quantity in stock:", ""); int quantity = 0; int.TryParse(quantityText, out quantity); product.Stock = quantity.ToString(); } else { WriteLogEvent(url, "quantity in stock: is not exist in quantity node"); } } } var count = (from prd in Products where prd.SKU == product.SKU select prd).FirstOrDefault(); if (count == null) { product.URL = url; //double priceCheck = 0; //double minimumPrice = 1.5; //double.TryParse(product.Price, out priceCheck); //if (priceCheck > minimumPrice) Products.Add(product); } } catch { } } } else { WriteLogEvent(url, "App failed to read product on given url"); } }
public void GetProductInfo(HtmlAgilityPack.HtmlDocument _doc, string url) { BusinessLayer.Product product = new BusinessLayer.Product(); try { #region title if (_doc.DocumentNode.SelectNodes("//meta[@property=\"og:title\"]") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//meta[@property=\"og:title\"]")[0].Attributes) { if (attr.Name == "content") product.Name = System.Net.WebUtility.HtmlDecode(attr.Value); } } else if (_doc.DocumentNode.SelectNodes("//h1[@itemprop=\"name\"]") != null) product.Name = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//h1[@itemprop=\"name\"]")[0].InnerText.Trim()); else WriteLogEvent(url, "title not found"); #endregion title #region price if (_doc.DocumentNode.SelectNodes("//div[@itemprop=\"price\"]") != null) product.Price = _doc.DocumentNode.SelectNodes("//div[@itemprop=\"price\"]")[0].InnerText.Replace("$", "").Trim(); else { product.Price = "0"; WriteLogEvent(url, "Price not found"); } #endregion price #region Brand if (_doc.DocumentNode.SelectNodes("//span[@class=\"brand-logo\"]//img") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//span[@class=\"brand-logo\"]//img")[0].Attributes) { if (attr.Name == "alt") { product.Brand = System.Net.WebUtility.HtmlDecode(attr.Value.Trim()); product.Manufacturer = System.Net.WebUtility.HtmlDecode(attr.Value.Trim()); } } if (product.Brand == "") { if (_doc.DocumentNode.SelectNodes("//div[@class=\"brand-logo\"]//a") != null) { product.Brand = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"brand-logo\"]//a")[0].InnerText.Trim()); product.Manufacturer = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"brand-logo\"]//a")[0].InnerText.Trim()); } else WriteLogEvent(url, "Brand not found"); } } else if (_doc.DocumentNode.SelectNodes("//div[@class=\"brand-logo\"]//a") != null) { product.Brand = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"brand-logo\"]//a")[0].InnerText.Trim()); product.Manufacturer = System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"brand-logo\"]//a")[0].InnerText.Trim()); } else WriteLogEvent(url, "Brand not found"); #endregion Brand #region Category if (_doc.DocumentNode.SelectNodes("//span[@property=\"itemListElement\"]//a") != null) { try { product.Category = System.Net.WebUtility.HtmlDecode("BBYCA" + _doc.DocumentNode.SelectNodes("//span[@property=\"itemListElement\"]//a")[1].InnerText.Trim()); } catch { WriteLogEvent(url, "Category not found"); } } else WriteLogEvent(url, "Category not found"); #endregion Category product.Currency = "CAD"; #region description string Description = ""; if (_doc.DocumentNode.SelectNodes("//div[@class=\"tab-overview-item\"]") != null) { foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//div[@class=\"tab-overview-item\"]")) { Description = Description + " " + node.InnerText.Trim(); } Description = Removeunsuaalcharcterfromstring(StripHTML(Description).Trim()); try { if (Description.Length > 2000) Description = Description.Substring(0, 1997) + "..."; } catch { } product.Description = System.Net.WebUtility.HtmlDecode(Description.Replace("Â", "")); } else WriteLogEvent(url, "Description not found"); #endregion description #region BulletPoints string Feature = ""; string Bullets = ""; HtmlNodeCollection collection = _doc.DocumentNode.SelectNodes("//ul[@class=\"std-tablist\"]//li"); if (collection == null) collection = _doc.DocumentNode.SelectNodes("//ul[@class=\"std-tablist nobpadding\"]//li"); if (collection != null) { string Header = ""; string Value = ""; int PointCounter = 1; foreach (HtmlNode node in collection) { try { Header = System.Net.WebUtility.HtmlDecode(node.SelectNodes(".//span")[0].InnerText.Trim()); Value = System.Net.WebUtility.HtmlDecode(node.SelectNodes(".//div")[0].InnerText.Trim()); if (Value != "") { if (Header.ToLower() == "color" || Header.ToLower() == "colour") product.Color = Value; else if (Header.ToLower() == "size") product.Size = Value; else if (Header.ToLower() == "appropriate ages") { if (Value.ToLower().Contains("year")) product.AgeUnitMeasure = "Year"; else product.AgeUnitMeasure = "Month"; string childAge = System.Net.WebUtility.HtmlDecode(Value); childAge = Regex.Replace(childAge, @"[^\d]", String.Empty); int Age = 0; int.TryParse(childAge, out Age); product.MinimumAgeRecommend = Age == 0 || Age > 50 ? 1 : Age; } Feature = " " + Header + " " + Value; if (Feature.Length > 480) Feature = Feature.Substring(0, 480); if (Bullets.Length + Feature.Length + 2 <= PointCounter * 480) Bullets = Bullets + Feature + ". "; else { Bullets = Bullets + "@@" + Feature + ". "; PointCounter++; } } } catch { } } if (!string.IsNullOrEmpty(Bullets)) Bullets = Bullets.Trim(); } else WriteLogEvent(url, "BulletPoints not found"); #region ItemsInBox if (_doc.DocumentNode.SelectNodes("//div[@class=\"tab-content-right dynamic-content-column\"]//li") != null) Bullets = Bullets + "@@" + System.Net.WebUtility.HtmlDecode(_doc.DocumentNode.SelectNodes("//div[@class=\"tab-content-right dynamic-content-column\"]//li")[0].InnerText) + ". "; if (Bullets.Length > 0) { Bullets = Removeunsuaalcharcterfromstring(StripHTML(Bullets).Trim()); string[] BulletPoints = Bullets.Split(new string[] { "@@" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < BulletPoints.Length; i++) { if (i == 0) product.Bulletpoints1 = BulletPoints[i].ToString(); if (i == 1) product.Bulletpoints2 = BulletPoints[i].ToString(); if (i == 2) product.Bulletpoints3 = BulletPoints[i].ToString(); if (i == 3) product.Bulletpoints4 = BulletPoints[i].ToString(); if (i == 4) product.Bulletpoints5 = BulletPoints[i].ToString(); } } if (string.IsNullOrEmpty(product.Description)) { product.Description = product.Name; if (string.IsNullOrEmpty(product.Bulletpoints1)) product.Bulletpoints1 = product.Name; } else if (string.IsNullOrEmpty(product.Bulletpoints1)) { if (product.Description.Length >= 500) product.Bulletpoints1 = product.Description.Substring(0, 497); else product.Bulletpoints1 = product.Description; } #endregion ItemsInBox #endregion BulletPoints #region Image string Images = ""; if (_doc.DocumentNode.SelectNodes("//div[@id=\"pdp-gallery\"]//img") != null) { foreach (HtmlAttribute attr in _doc.DocumentNode.SelectNodes("//div[@id=\"pdp-gallery\"]//img")[0].Attributes) { if (attr.Name == "src") Images = attr.Value.Trim(); } } else WriteLogEvent(url, "Main Images not found"); foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//script")) { if (node.InnerText.Contains("pdpProduct")) { try { string script = "{\"" + node.InnerText.Substring(node.InnerText.IndexOf("pdpProduct")).Replace("//]]>", ""); script = script.Substring(0, script.IndexOf("if(config)")).Trim(); script = script.Substring(0, script.Length - 1); RootObject deserializedProduct = JsonConvert.DeserializeObject<RootObject>(script.Trim()); Images = ""; product.SKU = "BBYCA" + deserializedProduct.pdpProduct.sku; product.parentsku = "BBYCA" + deserializedProduct.pdpProduct.sku; int ImageCounter = 0; foreach (AdditionalMedia image in deserializedProduct.pdpProduct.additionalMedia) { if (image.mimeType.ToLower() == "image") { ImageCounter++; Images = Images + image.url + ","; } if (ImageCounter >= 9) break; } if (Images.Length > 0 && Images.Contains(",")) Images = Images.Substring(0, Images.Length - 1); } catch { WriteLogEvent(url, "Json conversion failed for PDPproduct script"); } break; } } product.Image = Images; #endregion Image product.Isparent = true; #region sku if (product.SKU == "") { if (_doc.DocumentNode.SelectNodes("//span[@itemprop=\"productid\"]") != null) { product.SKU = "BBYCA" + _doc.DocumentNode.SelectNodes("//span[@itemprop=\"productid\"]")[0].InnerText; product.parentsku = "BBYCA" + _doc.DocumentNode.SelectNodes("//span[@itemprop=\"productid\"]")[0].InnerText; } else WriteLogEvent(url, "SKU not found"); } #endregion sku product.Stock = "1"; product.URL = url; #region UPC if (_doc.DocumentNode.SelectNodes("//div[@class=\"tab-overview-item\"]") != null) { foreach (HtmlNode node in _doc.DocumentNode.SelectNodes("//div[@class=\"tab-overview-item\"]")) { string Innertext = System.Web.HttpUtility.HtmlDecode(node.InnerText.ToLower()).ToLower(); if (Innertext.Contains("upc:")) { string UPC = GetUPC(Innertext.Substring(Innertext.IndexOf("upc:")).Replace("upc:", "").Trim()); if (UPC.Length > 0) product.UPC = UPC; break; } } } #endregion UPC if (product.Brand.ToUpper() != "SOLOGEAR") Products.Add(product); } catch { } }