user_1856538_
user_1856538_

Reputation: 149

Loading ajax web page content with a webbrowser control

I'm using WebBrowser control for parsing a website.The results are good but I have problems for those kind of websites that require ScrollDown to load entire pages Via Ajax.I Tried to fire the "DocumentCompleted" event but seems that for this step the document is already loaded in control and just the top part (I mean without scrolling). I also tried to send keys and force scroll down or execute javascript for various WebBrowser states but without success.

I need help,

Thanks,

Upvotes: 0

Views: 1240

Answers (1)

user_1856538_
user_1856538_

Reputation: 149

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

Upvotes: 1

Related Questions