private void btnActualPrice_Click(object sender, EventArgs e) { web.WebRequest webRequest = new web.WebRequest(); string otv = null; FileInfo file = new FileInfo("Копия остатки для bike18.xlsx"); ExcelPackage p = new ExcelPackage(file); ExcelWorksheet w = p.Workbook.Worksheets[1]; int q = w.Dimension.Rows; for (int i = 2; q > i; i++) { string name = w.Cells[i, 2].Value.ToString(); string article = w.Cells[i, 1].Value.ToString().Trim(); double price = (double)w.Cells[i, 4].Value; int priceInSite = formulaPrice(price); CookieContainer cookie = Authorizacion(); string token = tokenReturn(cookie); otv = webRequest.getRequest("https://my.tiu.ru/cabinet/product2/index/5187992?status=0", cookie); otv = webRequest.getRequest("https://my.tiu.ru/cabinet/product2/create?parent_group=5187992&group=5187992&next=https%3A%2F%2Fmy.tiu.ru%2Fcabinet%2Fproduct2%2Findex%2F5187992%3Fstatus%3D0", cookie); } }
private void UpdateTovar(CookieDictionary cookie) { ControlsFormEnabledFalse(); discountTemplate = nethouse.Discount(); otv = webRequest.getRequest("https://xn--80andaliilpdrd0d.xn--p1ai/shop/"); MatchCollection categories = new Regex("(?<=<li class=\"product-category col-md-4 col-sm-6\">)[\\w\\W]*?(?=<img)").Matches(otv); foreach (Match str in categories) { string urlCategories = str.ToString(); if (urlCategories.Contains("katalogi-bumazhnaya-produktsiya") || urlCategories.Contains("reklamnaya-produktsiya") || urlCategories.Contains("dvigateli-dizelnyie2")) { continue; } urlCategories = urlCategories.Replace("\">", "").Replace("<a href=\"", "").Trim(); otv = webRequest.getRequest(urlCategories); MatchCollection subCategories = new Regex("(?<=class=\"product-category col-md-4 col-sm-6\">)[\\w\\W]*?(?=<img src=)").Matches(otv); foreach (Match subStr in subCategories) { string urlSubCategories = subStr.ToString(); urlSubCategories = new Regex("(?<=<a href=\").*?(?=\">)").Match(urlSubCategories).ToString(); urlSubCategories = urlSubCategories.Replace("\">", "").Replace("<a href=\"", "").Trim(); GetArrayTovar(urlSubCategories, cookie); } MatchCollection tovars = new Regex("(?<=<a class=\"product-loop-title\" href=\").*?(?=\">)").Matches(otv); foreach (Match tovar in tovars) { List <string> product = new List <string>(); string url = tovar.ToString(); product = GetListTovar(url, cookie); if (product == null) { continue; } string nameProduct = product[0]; string articl = product[1]; string searchTovarInBike = nethouse.searchTovar(nameProduct, articl); if (searchTovarInBike == "" || searchTovarInBike == null) { discount = discountTemplate.Replace("\"", "\"\""); boldOpen = boldOpenCSV; WriteTovarInCSV(product); } else { discount = discountTemplate.Replace("\"\"", "\""); boldOpen = boldOpenSite; bool edits = false; string name = product[0]; string article = product[1]; string price = product[2]; string category = product[3]; string miniDescriptionText = product[4]; string slug = product[5]; string availability = product[6]; List <string> productB18 = nethouse.GetProductList(cookie, searchTovarInBike); string priceB18 = productB18[9]; if (price != priceB18) { productB18[9] = price; edits = true; } if (availability == "") { productB18[43] = "0"; edits = true; } if (productB18[43] == "0" && availability != "") { productB18[43] = "100"; edits = true; } if (productB18[42].Contains("&alsoBuy[0]=0") || productB18[42].Contains("&alsoBuy[0]=als")) { productB18[42] = nethouse.alsoBuyTovars(productB18); edits = true; } if (chekedSEO) { string titleText = titleTextTemplate; string descriptionText = descriptionTextTemplate; string keywordsText = keywordsTextTemplate; titleText = ReplaceSEO(titleText, name, article); descriptionText = ReplaceSEO(descriptionText, name, article); keywordsText = ReplaceSEO(keywordsText, name, article); if (titleText.Length > 255) { titleText = titleText.Remove(255); titleText = titleText.Remove(titleText.LastIndexOf(" ")); } if (descriptionText.Length > 200) { descriptionText = descriptionText.Remove(200); descriptionText = descriptionText.Remove(descriptionText.LastIndexOf(" ")); } if (keywordsText.Length > 100) { keywordsText = keywordsText.Remove(100); keywordsText = keywordsText.Remove(keywordsText.LastIndexOf(" ")); } productB18[11] = descriptionText; productB18[12] = keywordsText; productB18[13] = titleText; edits = true; } if (chekedMiniText) { string miniText = minitextTemplate; miniText = ReplaceNameTovar(name, miniText); miniText = miniDescriptionText + "<br >" + miniText; miniText = ReplaceSEO(miniText, name, article); productB18[7] = miniText; edits = true; } if (chekedFullText) { string fullText = fullTextTemplate; fullText = ReplaceNameTovar(name, fullText); fullText = ReplaceSEO(fullText, name, article); fullText = fullText.Replace("\"\"", "\""); productB18[8] = fullText; edits = true; } productB18 = ReplaceAmpersChar(productB18); if (edits) { nethouse.SaveTovar(cookie, productB18); countEdit++; } } } } System.Threading.Thread.Sleep(10000); string[] naSite1 = File.ReadAllLines("naSite.csv", Encoding.GetEncoding(1251)); if (naSite1.Length > 1) { nethouse.UploadCSVNethouse(cookie, "naSite.csv", tbLogin.Text, tbPassword.Text); } MessageBox.Show("Обновлено товаров: " + countEdit); ControlsFormEnabledTrue(); }