0

我正在使用 WebBrowser 控件来解析网站。结果很好,但对于那些需要 ScrollDown 通过 Ajax 加载整个页面的网站,我遇到了问题。我试图触发“DocumentCompleted”事件,但似乎对于这一步文档已经加载到控件中并且只是顶部(我的意思是没有滚动)。我还尝试发送键并强制向下滚动或执行各种 WebBrowser 状态的 javascript,但没有成功。

我需要帮助,

谢谢,

4

1 回答 1

1

I found the answer for this question.What I had to know is
in the following code:

 public partial class Form1 : Form      
 {
    bool finished=false;
    public Form1()
    {            
        InitializeComponent();
        this.WindowState=FormWindowState.Maximized;          
        webBrowser1.ScriptErrorsSuppressed=true;            
        this.Show();                                 
        Wait4Load();
        string aaa = webBrowser1.DocumentText;                 
    }   

     void webBrowser1_DocumentCompleted(objectsender,WebBrowserDocumentCompletedEventArgs e) 
     {
         if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
         {
             finished = true;
             button1.PerformClick();
         }
     }

     void Wait4Load() 
     {
        webBrowser1.DocumentCompleted+=new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);             
        button1.Click+=new EventHandler(button1_Click);         
       if(!finished) 
        {
            Application.DoEvents();
            Thread.Sleep(2000);
        } 
         finished = false;
     }

     void button1_Click(object sender, EventArgs e) 
     {           
       //footerWrapper
         while(webBrowser1.ReadyState != WebBrowserReadyState.Complete)
           Application.DoEvents();
         while(webBrowser1.IsBusy)
           Application.DoEvents();
           webBrowser1.Navigate("javascript:setTimeout(location.hash='#footerWrapper',2000)");     
         //Thread.Sleep(3000);
       finished=true;
     }       
}`
于 2012-12-14T20:38:42.730 回答