天天看點

WinForm開發浏覽器,WebBrowser擷取頁面内容,如何解決中文亂碼

最近用C#寫一個簡單的浏覽器,遇到一個小小的問題,即:在通過WebBrowser.DocumentText擷取的頁面内容是亂碼?百度了N久,也沒看到一個較好的解決辦法。通過反複的實驗,并總結網上各位同仁的思路,終于找到了解決的辦法。下面提供給大家,以供參考。

System.IO.StreamReader getReader = new System.IO.StreamReader(this.webBrowser.DocumentStream, System.Text.Encoding.GetEncoding("gb2312"));

string gethtml = getReader.ReadToEnd();

注意:我這兒使用的不是DocumentText屬性擷取的頁面内容。