CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    20

    Post WebBrowser - download page without displaying it

    hi, my app have to visit many pages and i want to optimize it a little bit,
    i have already disabled images/videos/sounds downloading(i care only about html content), is there a way to download page with webbrowser but do not display it ? i am well aware of httpwebrequest etc. but html content downloaded this way is different from browser source code of website, probably something with ajax etc

    EDIT:
    solution where i dont need webbrowser, and downloaded html content will be exactly the same as browser source will be much more appreciated
    Last edited by sv13; April 20th, 2010 at 10:49 AM.

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: WebBrowser - download page without displaying it

    You can do this from the code-behind to get the HTML of a webpage...

    Code:
    private void button1_Click(object sender, EventArgs e)
    {
        WebBrowser browser = new WebBrowser();
        browser.Navigate("http://www.google.com");
        browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
    }
    
    void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser b = (WebBrowser)sender;
        string response = b.DocumentText;
        
        // response will now contain the HTML from the page.
    }
    ===============================
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured