public void ParseProductsFromPage(string url, int index = 0) { string baseUrl = url; if (index != 0) { url += "/page=" + index + "/"; } ThreadDelay.Delay(); try { IHtmlDocument document; var divsWithProduct = GetPageWithProduct(url, out document); GetProductsFromPage(divsWithProduct); var paginator = document.GetElementsByClassName("paginator-catalog"); string page = GetNumberPage(paginator); if (page != "") { ParseProductsFromPage(baseUrl, int.Parse(page)); } } catch (Exception ex) { } }
private void AddProduct(IElement div, string url) { ThreadDelay.Delay(); var product = CreateInstanseOfProduct(div, url); if (product != null) { if (_context != null) { AddToDBContext(product); } } }
public Product GetProductWithoutProxy(string url) { ThreadDelay.Delay(); var splitedUrl = url.Split('/'); var ProductId = splitedUrl[splitedUrl.Length - 2].Remove(0, 1); string ApiUrl = "https://rozetka.com.ua/recent_recommends/action=getGoodsDetailsJSON/?goods_ids=" + ProductId; WebRequest WR = WebRequest.Create(ApiUrl); WR.Method = "GET"; Product product = GetProductInstance(WR, url); return(product); }
public void ParseProductsFromPage(string url, int index = 0) { if (index != 0) { url += "?page=" + index; } ThreadDelay.Delay(); string baseUrl = url; HtmlParser parser = new HtmlParser(); var parseElement = parser.ParseDocument(GetHtml(url)); var divsWithProduct = parseElement.GetElementsByClassName("product-listing")[0] .GetElementsByClassName("product-item"); AddProducts(divsWithProduct, url); string page = GetPage(parseElement); if (page != "") { ParseProductsFromPage(baseUrl, int.Parse(page)); } }
public Product GetProduct(string url, ref List <string> proxyList) { ThreadDelay.Delay(); var splitedUrl = url.Split('/'); var ProductId = splitedUrl[splitedUrl.Length - 2].Remove(0, 1); string ApiUrl = "https://rozetka.com.ua/recent_recommends/action=getGoodsDetailsJSON/?goods_ids=" + ProductId; Product product = new Product(); foreach (var proxy in proxyList) { try { WebRequest WR = WebRequest.Create(ApiUrl); WR.Method = "GET"; SetProxy(ref WR, proxy); product = GetProductInstance(WR, url); return(product); } catch (Exception ex) { } } return(product); }