Question about grabbing webpage using WebBrowser Control. [modified]
-
Hi All, I want to load a page using WebBrowser Control (see code below). I try to get the page content through DocumentText property in "DocumentCompleted" event handler, but it seems that the event won't be triggered. The "Navigated" event won't be triggered either. However, the "Navigating" event does. I used to use HttpWebRequest/HttpWebResponse to grab webpage content, however, the drawback is that I can't get the full loaded page through it. What I mean by this is that maybe some javascript will execute to modify elements on the page after it's loaded, I call this page as full loaded page. I think using WebBrowser Control can overcome this drawback. It's just like a browser, and it'll execute those javascript after loading the page. But I can't make this control work correctly. Could anyone help me? I'm very appreciate. Thanks Jie using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace ConsoleApplication1 { class Program { static WebBrowser wb; [STAThread] static void Main(string[] args) { Go(); } private static void Go() { wb = new WebBrowser(); wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted); wb.Navigating +=new WebBrowserNavigatingEventHandler(wb_Navigating); wb.Navigated += new WebBrowserNavigatedEventHandler(wb_Navigated); wb.Navigate("http://www.google.com"); Console.ReadLine(); } static void wb_Navigating(object sender, WebBrowserNavigatingEventArgs e) { Console.WriteLine("Navigating"); } static void wb_Navigated(object sender, WebBrowserNavigatedEventArgs e) { Console.WriteLine("Navigated"); } static void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { Console.WriteLine("DocumentCompleted"); Console.WriteLine(wb.DocumentText); } } } -- modified at 10:06 Thursday 14th September, 2006