我想抓一个网页里的数据
可是那个网页禁止右键,禁止查看源代码,禁止保存,连临时文件都不生成我一开始用webbrowser这个控件,用documentText之类的就报错,说无法找到文件后来我用这个
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webBrowser1.Url.ToString());//webBrowser1.Url.ToString() 这是webbrowser控件里当前文档的url它又出异常:405 错误直接用url,不用上面的那种url就出"重定向次数太多"(他是用了url重写)各位有什么解决方法我在这跪求了,解决了,必以全部分赠送

解决方案 »

  1.   

    private void webBrowser1_DocumentComplete(object sender, BrowserExtendedDocumentCompleteEventArgs e)
            {
                try
                {
                    UnsafeNativeMethods.IWebBrowser2 wb = (UnsafeNativeMethods.IWebBrowser2)e.AutomationObject;
                    //IWebBrowser2 wb = (IWebBrowser2)e.AutomationObject;
                    if (wb != null)
                    {
                        //Unable to cast COM object of type 'System.__ComObject' to 
                        //class type 'mshtml.HTMLDocumentClass'. 
                        //COM components that enter the CLR and do not support IProvideClassInfo 
                        //or that do not have any interop assembly registered will 
                        //be wrapped in the __ComObject type. Instances 
                        //of this type cannot be cast to any other 
                        //class; however they can be cast to interfaces 
                        //as long as the underlying COM component supports 
                        //QueryInterface calls for the IID of the interface.
                        //when casting wb.Document to HTMLDocumentClass
                        mshtml.DispHTMLDocument ihtmldoc2 = (mshtml.DispHTMLDocument)wb.Document;
                        ihtmldoc2.onmousedown = "";//enable mouse click for debugging
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                if (webBrowser1.ReadyState != WebBrowserReadyState.Complete) return;
                /*
                foreach(HtmlWindow hw in webBrowser1.Document.Window.Frames)
                {
                    HTMLDocumentClass hdcWebBrowser = (HTMLDocumentClass)hw.Document.DomDocument;
                    hdcWebBrowser.onmousedown = "";//enable mouse click for debugging                
                }*/
                timer1.Start();for how to handle the documentcomplete event, see www.codeproject.com/csharp/ExtendedWebBrowser.asp
      

  2.   

    直接用webBrowser1.Document这个然后在读出里面的内容就可以了