C # get the content source code of WebBrowser


System.Windows.Forms.WebBrowserIt is a simple web browser component provided in WinForm framework. The browser kernel is the IE kernel of the system, and the version depends on the IE version. Suppose there is a WebBrowser control with a name attribute value of WebBrowser1. The method to obtain the web content source code is as follows:

using System;
using System.IO;
using System.Windows.Forms;
using System.Text;

StreamReader getReader = new StreamReader(webBrowser1.DocumentStream, Encoding.GetEncoding(webBrowser1.Document.Encoding));
string gethtml = getReader.ReadToEnd();