Originally Posted by
Devils Child
i tried that and somehow, the WebBrowser object does not seem to contain any data.
example:
Code:
WebBrowser web = new WebBrowser();
web.Navigate("http://www.google.com/");
Thread.Sleep(5000);
// breakpoint here
it has null's and ""s everywhere.
what am i doing wrong?
The reason is that with Thread.Sleep() you will simply block the current thread, so it is not that reliable.
You have to do something like this:
Code:
private void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
completedLoading = true;
}
public void LoadPage(string url, bool wait = true)
{
completedLoading = false;
browser.Navigate(new Uri(url));
delaying = true;
delayThread = new Thread(new ParameterizedThreadStart(delayDel));
delayThread.Start(SecDelaying);
while (delaying)
Application.DoEvents();
while (!completedLoading)
Application.DoEvents();
}
public static void Delay(object sec)
{
Thread.Sleep((int)sec * 1000);
delaying = false;
}
The first part, the most important, while ensure that the Document is completed, thus the page loaded. BUT, sometimes it loads more than once. That is why I have an additional delay. Note that the Delay function is executed from another Thread (delayThread) so it doesn't stop current thread.
Just a note, I had problems finding links even using the method above. For example I was trying to get links from search engine pages. For most of the part I could, but still somethings were missing, so it might not always be possible to do what you want.