Copy all text from webbrowser control

14,367

Solution 1

You use the DocumentText property or the WebBrowser control.

This property is what holds the HTML of the site you have navigated to.

Update: (following comments)

If you want to parse the HTML and get the text parts of it, I suggest you use the HTML Agility Pack.

Solution 2

David Walker's method is great when one don't need any info from the header nor non main part of the webpage. if one need something outside inner text, there is only two options, one is to parse with "getElement". the other one is issue commands (Document.ExecCommand) to webbrowser to select all and copy to clipboard:

wb.Document.ExecCommand("SelectAll", false, null);
wb.Document.ExecCommand("Copy", false, null);

then finally string content=clipboard.getText();

Please note the spelling and syntax may not be correct, I'm recalling from my memory

Solution 3

string browserContents = webBrowser.Document.Body.InnerText;
Share:
14,367
Alex Gordon
Author by

Alex Gordon

Check out my YouTube channel with videos on Azure development.

Updated on June 05, 2022

Comments

  • Alex Gordon
    Alex Gordon almost 2 years

    Is it possible to scrape all the text from a site that was navigated to by WebBrowser control without looking at the source?

  • Alex Gordon
    Alex Gordon about 14 years
    oded, i do not want to look at the html, i only want to look at the text that the user sees
  • Alex Gordon
    Alex Gordon about 14 years
    no i dont want to parse the html, i just want the same result as if you hit ctrl A and copy and paste all the text
  • Oded
    Oded about 14 years
    Um. That's what you will get by parsing the HTML.
  • Skyfish
    Skyfish over 3 years
    Thanks for putting me onto the scent David. If you want to preserve the formatting like I do, use webBrowser.Document.Body.InnerHtml;