0

I have made a HttpWebRequest to a page to get the page containing a table that I want to parse, But the problem is that there are some JavaScripts that needs to run before being able to access the table. So Now I want to have a WebBrowser control and let the page load in the webbrowser and then read the html content of it to be parsed! Any heads up how I can do this?

Also when I load the page in WebBrowser control it gives me some javascript error, and once I pass all those errors it will loads the full page. Is there anyway to bypass those errors ?

thank you

Rob Schneider
  • 679
  • 4
  • 13
  • 27

1 Answers1

0

You could set ScriptErrorsSuppressed to true. This suppresses all dialogs displayed by WebBrowser control. In case where you want to selectively ignore errors you would have to subscribe to Window.Error event on the document. For more details check MSDN page

Alternatively you could use Html Agility Pack. in which case you wouldn't have to use WebBrowser control at all.

Example:

    HtmlDocument htmlDocument = null;
    HtmlWeb htmlWeb = new HtmlWeb();
    htmlWeb.PreHandleDocument = new HtmlWeb.PreHandleDocumentHandler((document) => htmlDocument = document );
    htmlWeb.Load(url, "GET");

    foreach (HtmlNode item in htmlDocument.DocumentNode)
    {
        // find your table node
    }
Vijay Sirigiri
  • 4,653
  • 29
  • 31
  • Hey thank you, I haven't tried this but on this post I showed what I have done, Can you have a look at it and tell me if that is possible with your method ? http://stackoverflow.com/questions/11491170/unexpected-behaviour-while-using-httpwebrequest-on-a-form-to-obtain-a-table-for – Rob Schneider Jul 17 '12 at 09:45
  • Problem is that some javascripts are preventing the table to load when I do httpwebrequest – Rob Schneider Jul 17 '12 at 09:45