private int GetProductInfoSku(HtmlAgilityPack.HtmlDocument _doc, ref ProductInfoSku PIS, ref List <string> images, ref List <String_String> name_and_des_title_img) { /* try * {*/ HtmlNode jProductInfoSku = _doc.GetElementbyId("j-product-info-sku"); IEnumerable <HtmlNode> proItems = jProductInfoSku.Elements("dl"); foreach (HtmlNode proItem in proItems) { string name = ""; //Gonna be added to NameVal_String NameValueCollection skuList = new NameValueCollection(); int hasIMGTag = 0; name = proItem.Element("dt").InnerText.Replace(":", ""); HtmlAgilityPack.HtmlNode jSkuList = proItem.Element("dd").Element("ul"); IEnumerable <HtmlNode> itemSkus = jSkuList.Elements("li"); //itemSku: li element contains class item-sku-color foreach (HtmlNode itemSku in itemSkus) { string dataSkuId = itemSku.FirstChild.Attributes["data-sku-id"].Value; string title; if (itemSku.FirstChild.Attributes.Contains("title")) { title = itemSku.FirstChild.Attributes["title"].Value; } else { title = itemSku.FirstChild.InnerText; } skuList.Add(dataSkuId, title); //Images of colors if (itemSku.FirstChild.Descendants("img").Count <HtmlNode>() > 0) { if (itemSku.FirstChild.Element("img").Attributes.Contains("bigpic")) { string bigpicWithTail = itemSku.FirstChild.Element("img").Attributes["bigpic"].Value; string bigpicWithoutTail = bigpicWithTail.Remove(bigpicWithTail.LastIndexOf('_')); images.Add(bigpicWithoutTail); string values_s = "<tr><td>" + name + ": " + title + "</td><td><img width='480' height='480' src='" + bigpicWithTail + "'></td></tr>"; name_and_des_title_img.Add(new String_String(name, values_s)); } hasIMGTag = 1; } //Background colors else if (itemSku.FirstChild.Descendants("span").Where(n => n.Attributes.Contains("class") && n.Attributes["class"].Value.Contains("sku-color-")).Count <HtmlNode>() > 0) { MessageBox.Show(itemSku.FirstChild.Descendants("span").First().OuterHtml); HtmlNode backgroundColorCSSElem = itemSku.FirstChild.Descendants("span").Where(n => n.Attributes.Contains("class") && n.Attributes["class"].Value.Contains("sku-color-")).First(); string className = backgroundColorCSSElem.Attributes["class"].Value; string colorStyle = BackgroundColorSelector(className); if (colorStyle == "") { return(-2); } string values_s = "<tr><td>" + name + ": " + title + "</td><td width='480' height='480' style='" + BackgroundColorSelector(className) + "'></td></tr>"; name_and_des_title_img.Add(new String_String(name, values_s)); } else if (name.ToLower() == "color") { MessageBox.Show("Color not found! Liên hệ https://www.facebook.com/letruongquy96 \nOuterHTML: " + itemSku.InnerHtml); return(-1); } } NameVal_String skuList_hasIMGTag = new NameVal_String(skuList, hasIMGTag); PropertyItem tempPI = new PropertyItem(name, skuList_hasIMGTag); PIS.Add(tempPI); } /*} * catch(Exception ex) * { * MessageBox.Show("GetProductInfoSku: " + ex.Message); * return -7; * }*/ return(0); }
public PropertyItem(string _name, NameVal_String _skuList_hasIMGTag) { this.name = _name; this.skuList_hasIMGTag = _skuList_hasIMGTag; }