private void start() { my_delegate = new add_text(add_text_method); for (int i = this.first_page - 1; i < this.last_page; i++) { string content; if (i == 0) { content = getRequest(UrlTxtBox.Text); } else { content = getRequest(UrlTxtBox.Text + this.param_separator + "PAGEN_5=" + (i + 1)); } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(content); HtmlAgilityPack.HtmlNodeCollection c = doc.DocumentNode.SelectNodes("//div[@class='mid pt']/h3[@class='h3 mt']/a"); List <string> url_news = new List <string>(); int g = 0; if (c != null) { foreach (HtmlAgilityPack.HtmlNode n in c) { //url_news.Add(n.Attributes["href"].Value); /*if(n.Attributes["href"] != null) * { * string url = n.Attributes["href"].Value; * * rtb_output.Text += url; * }*/ //url_news.Add(n.Attributes["href"].Value); url_news.Add(n.InnerText.Trim() + "\n"); rtb_output.Text += (url_news[g]); g++; } } //rtb_output.Invoke(a_delegate, new object[] { array_unique(rtb_output.Lines) }); //tr.Abort(); } }
/// <summary> /// Основной метод парсинга. Вызывается в отдельном потоке. /// </summary> public void start(HtmlAgilityPack.HtmlDocument doc, int cnt, CancellationToken token) { byte ascii = 10; char ch = (char)ascii; my_delegate = new add_text(add_text_method); for (int j = 2; j < cnt + 1; j++) { token.ThrowIfCancellationRequested(); string c4Value; string c5Value = ""; string c8Value = ""; string c88Value = ""; string res = ""; HtmlNodeCollection c = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[1]"); HtmlNodeCollection c1 = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[2]"); HtmlNodeCollection c2 = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[3]"); HtmlNodeCollection c3 = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[4]"); HtmlNode c4 = doc.DocumentNode.SelectSingleNode("//table[@class='wikitable sortable']//tr[" + @j + "]//td[5]"); HtmlNodeCollection c5 = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[6]/span[1]"); HtmlNodeCollection c6 = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[7]"); HtmlNodeCollection c8 = doc.DocumentNode.SelectNodes("//table[@class='wikitable sortable']/tr[" + @j + "]/td[9]/a[1]/img[1]"); if (c4 == null) { c4Value = ""; } else { try { c4Value = c4.InnerText.Split(ch)[2]; } catch { c4Value = c4.InnerText; } } if (c5 == null) { c5Value = ""; } else { c5Value = c5[0].InnerText; } if (c8 == null) { c8Value = ""; c88Value = ""; } else { c8Value = c8[0].Attributes["src"].Value; c88Value = c8[0].Attributes["alt"].Value; } rtb_output.Invoke(my_delegate, new object[] { c[0].InnerText.Trim() + ";" + c1[0].InnerText.Trim().Replace(" ", " ").Replace(";", "|") + ";" + c2[0].InnerText.Trim().Replace(";", "|") + ";" + c3[0].InnerText.Trim() + ";" + c4Value.Replace(" ", " ") + ";" + c5Value.Trim() + ";" + c6[0].InnerText.Trim().Replace(" ", "") + ";" + c88Value + "\n" }); if (c8Value != "") { res = Load_Image1(c[0].InnerText.Trim(), c8Value, "-1"); if (res == "-1") { Load_Image1_reserve(c[0].InnerText.Trim(), "https:" + c8Value.Replace("180px", "6400px"), "-1"); } } // Запускаем событие ProgressChanged(j); } }