public string GetNextArticle(string url) { var localCountAttempts = 0; string result = null; while (localCountAttempts < _countAttempts) { try { Thread.Sleep((int)_miliSecondForSleeping); result = _parser.GetNextArticle(url); if (result != null) { return(result); } localCountAttempts += 1; } catch (OpenQA.Selenium.NoSuchWindowException) { throw; } catch (Exception) { Restart(); localCountAttempts += 1; if (localCountAttempts == _countAttempts) { throw; } } } return(result); }
private void StartParsing(IParse parser) { var firstUrl = URLTextBox.Text; var nextUrl = firstUrl; var countArticles = Convert.ToInt32(PagesCounTextBox.Text); ChangeControlInMainUi(progressBar1, () => progressBar1.Value = 0); ChangeControlInMainUi(progressBar1, () => progressBar1.Maximum = countArticles); for (; progressBar1.Value < countArticles && nextUrl != null; ChangeControlInMainUi(progressBar1, () => progressBar1.Value += 1)) { ChangeControlInMainUi(PersentLabel, () => PersentLabel.Text = $@"Парсится {progressBar1.Value} статья из {progressBar1.Maximum}({(progressBar1.Value) * 100 / progressBar1.Maximum}%)"); var result = parser.ParseSpecificArticle(nextUrl); ChangeControlInMainUi(URLTextBox, () => URLTextBox.Text = nextUrl); if (result != null) { _persons.AddRange(result); foreach (var item in result) { ChangeControlInMainUi(ReturnedEmailDataGrid, () => ReturnedEmailDataGrid.Rows.Add(item.Fio, item.Email)); } } nextUrl = parser.GetNextArticle(nextUrl); } }