没有表单的Web浏览器控件 [英] Webbrowser control without a form

查看:88
本文介绍了没有表单的Web浏览器控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在创建一个通用的反向链接检查器。它工作正常,除非主机试图阻止与noscript案件之类的东西刮擦。我的解决方案是在浏览器控件中加载页面,但我不能让dang的东西工作。它开始导航但似乎永远不会完成。








如果您觉得这样,请原谅我是不道德的。随意忽略我的问题。我发现它不是不道德的,因为除了检查页面是否有链接到我们自己的网站之外,我不会做任何其他事情。

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.

引用:

seo和主机之间的军备竞赛一直持续

The arms race between seo and host rages ever onward





我尝试过:





What I have tried:

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 "";
}

推荐答案

的调用e.WaitOne()阻止当前线程,直到设置了 AutoResetEvent WebBrowser 控件将引发其事件以响应在当前线程上处理的窗口消息。我相信你可以看到那里的小问题! :)



快速而肮脏的解决方案是使用 Application.DoEvents

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:
browser.Navigate(url.ToString());
while (!e.WaitOne(0))
{
    Application.DoEvents();
}


这篇关于没有表单的Web浏览器控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆