public string TranslateStock() { return(Translator.ManualTranslate(this.Stock)); }
public Product ParseBodenProduct(string url) { this.LoadWebPage(url); // Prepare the product object. HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(this.driver.PageSource); Product product = new Product(); product.URL = url; HtmlNode rootNode = doc.DocumentNode; product.Brand = @"Boden"; product.URL = url; // Parse the product id from the url. string[] ss = url.Split('/'); product.ProductID = ss[ss.Length - 2]; // Parse the product name HtmlNode currentNode = rootNode.SelectSingleNode(@"//h1[@class=""pdpProductTitle""]"); if (currentNode != null) { string productTitle = currentNode.InnerText.Trim(); product.Title = productTitle; product.TitleCN = Translator.Translate(productTitle); } // Parse the sex and category. HtmlNode breadNode = rootNode.SelectSingleNode(@"//div[@class=""breadcrumb""]"); if (breadNode != null) { HtmlNodeCollection categoryNodes = breadNode.SelectNodes(@".//li"); // Parse the gender. product.Gender = ParseBodenGenderString(categoryNodes[1].InnerText); int num = categoryNodes.Count; // Parse the category. if (num > 2) { string categoryStr = categoryNodes[num - 2].InnerText.Trim(); product.Category = ParseBodenCategoryString(categoryStr); } } // Parse the description and material. currentNode = rootNode.SelectSingleNode(@"//div[@class=""tabContent pdpProductPnl a-slide""]"); if (currentNode != null) { string productDescription = WebUtility.HtmlDecode(currentNode.InnerText.Trim()); string[] desStrings = productDescription.Split('\n'); product.Description = desStrings[0].Trim(); product.DescriptionCN = Translator.Translate(product.Description); if (ss.Length > 1) { product.Material = String.Join(@"", desStrings.Skip(1)).Trim().Replace(@"\n", @" ").Replace(@"\r", @""); product.MaterialCN = Translator.Translate(product.Material); } else { product.Material = @""; product.MaterialCN = @""; } } // Parse the image links HtmlNode imgContainerNode = rootNode.SelectSingleNode(@"//div[@class=""imageryImagesContainer""]"); if (imgContainerNode != null) { IList <string> imgLinks = new List <string>(); HtmlNodeCollection imgNodes = imgContainerNode.SelectNodes(@".//img[@class=""cloudzoom""]"); foreach (HtmlNode imgNode in imgNodes) { imgLinks.Add(imgNode.Attributes["src"].Value); } product.ImageLinks = string.Join(@";", imgLinks); product.ThumbnailLink = imgLinks.First(); } product.InsertTime = DateTime.Now; product.UpdateTime = DateTime.Now; PriceInfo[] priceInfos = ParseBodenPrices(this.driver, this.wait); product.SetPriceInfos(priceInfos); // Parse the age info if (priceInfos.Length > 0) { Tuple <Single, Single> firstAge = ParseBodenAgeInfo(priceInfos.First().Size); Tuple <Single, Single> lastAge = ParseBodenAgeInfo(priceInfos.Last().Size); product.MinimumAge = firstAge.Item1; product.MaximumAge = lastAge.Item2; } return(product); }
public string TranslateSize() { return(Translator.ManualTranslate(this.Size)); }