Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am creating a generic "backlink" checker. It works fine unless the hosts try to prevent scraping with things like "noscript" cases. My solution is to load the page in a browser control, but I can't get the dang thing to work. It starts navigating but never seems to finish.




Forgive me if you feel this is unethical. Feel free to ignore my question. I don't find it unethical because I will not be doing anything else other than checking if the page has a link to our own sites.
Quote:
The arms race between seo and host rages ever onward


What I have tried:

C#
public string Window_Load(Uri url)
{
    var e = new AutoResetEvent(false);

    WebBrowser browser = new WebBrowser();

    browser.Navigating += (sender, args) =>
    {
        // hits this
        Console.WriteLine("navigating");
    };

    browser.Navigated += (sender, args) =>
    {
        // never hit
        Console.WriteLine("navigated");
    };

    browser.DocumentCompleted += (sender, args) =>
    {
        // never hit
        e.Set();

        browser.Dispose();
    };
    browser.AllowNavigation = true;

    browser.Navigate(url.ToString());

    e.WaitOne();

    return "";
}
Posted
Updated 4-Mar-16 4:49am

1 solution

The call to e.WaitOne() blocks the current thread until the AutoResetEvent is set. The WebBrowser control will raise its events in response to window messages processed on the current thread. I'm sure you can see the slight problem there! :)

The quick-and-dirty solution would be to use Application.DoEvents:
C#
browser.Navigate(url.ToString());
while (!e.WaitOne(0))
{
    Application.DoEvents();
}
 
Share this answer
 
Comments
Andy Lanng 4-Mar-16 10:52am    
Awesome. I thought it might have something to do with the thread it was running on.
I'll do some work to make the quick-and-dirty solution a little cleaner is my project ;)

Thanks!
Andy Lanng 4-Mar-16 11:24am    
dammit - vector smash

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900