C# 打印webBrowser打开的页面
1 this.webBrowser.Navigate(webBrowserUrl, tagerFrameName, postBuffer, heads); 2 this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(WebBrowser_DocumentCompleted); 3 4 void WebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 5 { 6 WebBrowser webBrowser = (WebBrowser)sender; 7 //WebBrowserReadyState.Interactive 和WebBrowserReadyState.Complete 时都会触发DocumentCompleted 8 if (webBrowser.ReadyState == WebBrowserReadyState.Complete) 9 { 10 //webBrowser1.DocumentText 获取的内容中文会乱码 11 //获取文档编码 12 Encoding encoding = Encoding.GetEncoding(webBrowser.Document.Encoding); 13 StreamReader stream = new StreamReader(webBrowser.DocumentStream, encoding); 14 File.WriteAllText(@"D:\mzwu.txt", stream.ReadToEnd(), Encoding.Unicode); 15 MessageBox.Show(DateTime.Now.ToString() + ": 页面内容获取完成! "); 16 } 17 }