I need to perform certain actions on the site (open the page, enter the login and password, click on the link in the page that opens, parse the received page) I decided to use WebBrowser. Open the page, log in - it turned out. But by clicking on the link, the page I need is no longer loaded into WebBrowser.Document, there is still the same page that opened after the login). That's the problem, what I'm doing is not how to get the final page. The code is:

public static class Web { static WebBrowser wb = new WebBrowser(); static int action_type; static void PageLoaded(object sender, WebBrowserDocumentCompletedEventArgs e) { switch (action_type) { case 0: // вводим данные и логинимся wb.Document.GetElementById("login").InnerText = "123"; wb.Document.GetElementById("passw").InnerText = "456"; action_type = 1; foreach (HtmlElement hh in wb.Document.GetElementsByTagName("input")) { if (hh.GetAttribute("value") == "Войти") hh.InvokeMember("click"); } break; case 1: // переходим по ссылке с текстом АБВГД action_type = 2; foreach (HtmlElement link in wb.Document.Links) { if (link.InnerText == "АБВГД") { string href = link.GetAttribute("href"); wb.Navigate(href); break; } } break; case 2: // смортим что тут есть // вот тут и проблема string s = ((WebBrowser)sender).DocumentText; break; } } public static void test() { wb.AllowNavigation = true; wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(PageLoaded); action_type = 0; wb.Navigate("сайт.html"); } } 
  • Did you check wb.ReadyState ? - VladD
  • I began to write the code in this way, but then I read that the method that I described above, that is, using the event itself, works more reliably. - Antykus
  • Well, you are supposed to check ReadyState in an event. Maybe you respond to the wrong message? - VladD

0