我要用WebBrowser去浏览网站,
因为速度要求,
要求不要去下载图片资源
那WebBrowser应该如何来实现
谢谢PS:是不下载图片资源,并不是说在WebBrowser中显示后把图片标签去掉谢谢

解决方案 »

  1.   

    http://bbs.csdn.net/topics/200056000
    http://msdn.microsoft.com/en-us/library/aa770041(VS.85).aspx 中的 Controlling Download and Execution
      

  2.   

            private void wbSite_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (this.wbSite.Document != null)
                {
                    var doc = this.wbSite.Document;
                    if (doc != null)
                    {
                        var imgs = doc.GetElementsByTagName("img");
                        //"edit_parent"
                        foreach (HtmlElement img in imgs)
                        {
                             img.SetAttribute("src", "");
                        }                }
                    return;
                }
            }我用这种方法,只是是网页加载后,再把图片去掉
    如果在在加,但还没有加载资源的时候去掉谢谢
      

  3.   

            private void wbSite_Navigating(object sender, WebBrowserNavigatingEventArgs e)
            {
                if (this.wbSite.Document != null)
                {
                    var doc = this.wbSite.Document;
                    if (doc != null)
                    {
                        var imgs = doc.GetElementsByTagName("img");
                        //"edit_parent"
                        foreach (HtmlElement img in imgs)
                        {
                                Console.WriteLine(img.InnerHtml);
                                img.SetAttribute("src", "");
                                img.SetAttribute("alt", "去除");
                        }
                        var links = doc.GetElementsByTagName("link");
                        foreach (HtmlElement link in links)
                        {
                            Console.WriteLine(link.InnerHtml);
                            link.SetAttribute("href", "去除");
                        }
                    }
                   
                }
    我用上面的方法的话,还是会在页面加载的时候显示图片和样式
    如何才能让WebBorswer不显示图片和CSS样式呢?
    PS:是在不去改IE设置的前题
    谢谢
      

  4.   

    一个比较dirty的方法,写NDIS驱动,或者利用Winpcap拦截mime是image/*的HTTP请求
      

  5.   

    Controlling Download and ExecutionThe WebBrowser Control gives you control over what it downloads, displays, and executes. To gain this control, you need to implement your host's IDispatch so it handles DISPID_AMBIENT_DLCONTROL. When the WebBrowser Control is instantiated, it will call your IDispatch::Invoke with this ID. Set pvarResult to a combination of following flags, using the bitwise OR operator, to indicate your preferences.* DLCTL_DLIMAGES, DLCTL_VIDEOS, and DLCTL_BGSOUNDS: Images, videos, and background sounds will be downloaded from the server and displayed or played if these flags are set. They will not be downloaded and displayed if the flags are not set.没试过,来自:
    WebBrowser Customization
    http://msdn.microsoft.com/en-us/library/aa770041(VS.85).aspx