private static void GetProductsDetail() { ChromeDriver drv = new ChromeDriver(); Console.WriteLine("Download begins."); int wiewed = 0;; int received = 0; var products = new List <WebProduct>(); int repeatCounter = 0; foreach (var code in ASINCodes) { wiewed++; try { #region Mapping(Seller Detail) Thread.Sleep(3000); repeatCounter = 0; Repeat: drv.Navigate().GoToUrl("https://www.amazon.com.tr/s?k=" + code); if (drv.PageSource.IndexOf("Website Temporarily Unavailable") != -1) { if (repeatCounter < 1) { Thread.Sleep(3000); repeatCounter++; goto Repeat; } else { continue; } } if (drv.PageSource.IndexOf("Server Busy") != -1) { if (repeatCounter < 1) { Thread.Sleep(3000); repeatCounter++; goto Repeat; } else { continue; } } try { HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(drv.PageSource.ToString()); if (document != null) { HtmlNodeCollection nodCol = document.DocumentNode.SelectNodes("//div[@data-asin]"); if (nodCol == null) { WebProduct product = new WebProduct() { StoreName = "Amazon", WinCoins = 0, InStock = true, StoreId = 1234, RequestTime = DateTime.Now, CargoDetail01 = "0", Barcode = code, Category = "", SubCategory = "", Brand = "", Sku = "Couldn't find it." }; products.Add(product); received++; GC.Collect(); } if (nodCol != null) { for (int i = 1; i < nodCol.Count; i++) { string asin = nodCol[i].Attributes["data-asin"].Value; if (!string.IsNullOrEmpty(asin)) { WebProduct product = new WebProduct() { StoreName = "Amazon", WinCoins = 0, InStock = true, StoreId = 1234, RequestTime = DateTime.Now, CargoDetail01 = "0", Barcode = code, Category = "", SubCategory = "", Brand = "" }; try { var skudoc = nodCol[i].SelectSingleNode(".//a[@class='a-link-normal a-text-normal']").InnerText.Trim(); product.Sku = skudoc; var urldoc = nodCol[i].SelectSingleNode(".//a[@class='a-link-normal a-text-normal']").Attributes["href"].Value; product.NewUrl = "https://amazon.com.tr" + urldoc; } catch (Exception ex) { } products.Add(CheckTurkishCharacters(product)); received++; GC.Collect(); } } } } } catch (Exception ex) { } #endregion } catch (Exception) { } Console.WriteLine("Toplam Ürün : {0} Bakılan Ürün : {1} Alınan Ürün(Satıcılı) : {2}", ASINCodes.Count, wiewed, received); GC.Collect(); } Console.WriteLine("Data preparing."); ConvertToDatatable(products); Console.WriteLine("Mission accomplished +respect."); drv.Quit(); Environment.Exit(0); }
private static WebProduct CheckTurkishCharacters(WebProduct model) { // 1 Characters in text WebProduct newModel = new WebProduct();; var temp = ""; foreach (PropertyInfo item in model.GetType().GetProperties()) { try { if (item.GetValue(model) is string) { temp = item.GetValue(model).ToString(); temp = temp.Replace("þ", "ş"); temp = temp.Replace("Þ", "Ş"); temp = temp.Replace("ý", "ı"); temp = temp.Replace("Ý", "İ"); temp = temp.Replace("ð", "ğ"); temp = temp.Replace("Ð", "Ğ"); temp = temp.Replace("'", "'"); // Just 2 characters in text; temp = temp.Replace("Ãœ;", "ç"); temp = temp.Replace("ı", "ı"); temp = temp.Replace("ÄŸ", "ğ"); temp = temp.Replace("ö", "ö"); temp = temp.Replace("ÅŸ", "ş"); temp = temp.Replace("ü", "ü"); temp = temp.Replace("Ç", "Ç"); temp = temp.Replace("Ä°", "İ"); temp = temp.Replace("ÄŸ", "Ğ"); temp = temp.Replace("Ö", "Ö"); temp = temp.Replace("ÅŸ", "Ş"); temp = temp.Replace("Ãœ", "Ü"); // 5 Characters in text temp = temp.Replace("ç", "ç"); temp = temp.Replace("ı", "ı"); temp = temp.Replace("ğ", "ğ"); temp = temp.Replace("ö", "ö"); temp = temp.Replace("ş", "ş"); temp = temp.Replace("ü", "ü"); temp = temp.Replace("Ç", "Ç"); temp = temp.Replace("İ", "İ"); temp = temp.Replace("Ð", "Ğ"); temp = temp.Replace("Ö", "Ö"); temp = temp.Replace("Ş", "Ş"); temp = temp.Replace("Ü", "Ü"); temp = temp.Replace("Ç", "Ç"); temp = temp.Replace("Ğ", "Ğ"); temp = temp.Replace("Ö", "Ö"); temp = temp.Replace("Ü", "Ü"); temp = temp.Replace("ç", "ç"); temp = temp.Replace("ö", "ö"); temp = temp.Replace("ü", "ü"); temp = temp.Replace("&", "&"); temp = temp.Replace("·", "-"); } else { continue; } } catch (Exception ex) { Console.WriteLine(ex.Message); } item.SetValue(model, temp); } return(model); }