private void Start() { try { ChromeOptions options = new ChromeOptions(); options.AddArgument("ignore-certificate-errors"); using (_driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options)) { _driver.Navigate().GoToUrl("https://www.emag.ro/televizoare/c?ref=hp_menu_quick-nav_190_1&type=category"); Thread.Sleep(2000); _productLinks = _driver.FindElementsByXPath("//div[@id='card_grid']//div[@class='card-v2-info']/a[contains(@class,'js-product-url')]") .Where(n => !string.IsNullOrEmpty(n.GetAttribute("href"))) .Select(n => n.GetAttribute("href")) .ToList() .Take(10); foreach (var link in _productLinks) { Thread.Sleep(2000); var product = ParseLink(link); EmagProducts.Add(product); } } } catch (Exception ex) { } }
private void StartWithProxies() { SearchForProxies(); bool retryProxy = true; for (int i = 0; i < proxies.Count && retryProxy; i++) { try { ChromeOptions options = new ChromeOptions(); Proxy proxy = new Proxy(); proxy.SslProxy = proxies[i]; proxy.Kind = ProxyKind.Manual; options.Proxy = proxy; options.AddArgument("ignore-certificate-errors"); using (_driver = new ChromeDriver(AppDomain.CurrentDomain.BaseDirectory, options)) { _driver.Navigate().GoToUrl("https://www.emag.ro/televizoare/c?ref=hp_menu_quick-nav_190_1&type=category"); Thread.Sleep(2000); _productLinks = _driver.FindElementsByXPath("//div[@id='card_grid']//a[contains(@class,'product-title')]") .Where(n => !string.IsNullOrEmpty(n.GetAttribute("href"))) .Select(n => n.GetAttribute("href")) .ToList(); if (_productLinks.Count() == 0) { continue; } foreach (var link in _productLinks) { try { var product = ParseLink(link); EmagProducts.Add(product); } catch (Exception ex) { //TODO:: log exception } } } } catch (Exception ex) { if (ex.Message.Contains("ERR_PROXY_CONNECTION_FAILED") || ex.Message.Contains("ERR_CONNECTION_RESET")) { retryProxy = true; } else { retryProxy = false; } } } }