日期:2014-05-18  浏览次数:21123 次

c# webbroswer控件 获取动态网页的输出内容
我知道html网页的内容可以通过webbroswer控件的document对象去获取,但是动态网页上的内容,用webbroswer控件,怎么获取得到呢?比如:
http://dkac.trillinux.org/dkac/dkac.php/?get=1&hostfile=1&net=gnutella2&ping=1&pv=4&client=RAZA2.5.5.0&getleaves=1&getnetworks=1&getclusters=0&getvendors=1&getuptime=1
这个网址的数据,很简单的显示在页面上,请问,怎么取出来呢?谢谢

------解决方案--------------------
private void button1_Click(object sender, EventArgs e)
{
WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
webBrowser.Navigate("http://www.mzwu.com/");
}

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser webBrowser = (WebBrowser)sender;
//WebBrowserReadyState.Interactive 和 WebBrowserReadyState.Complete 时都会触发DocumentCompleted
if (webBrowser.ReadyState == WebBrowserReadyState.Complete)
{
//webBrowser1.DocumentText 获取的内容中文会乱码
//获取文档编码
Encoding encoding = Encoding.GetEncoding(webBrowser.Document.Encoding);
StreamReader stream = new StreamReader(webBrowser.DocumentStream, encoding);
File.WriteAllText(@"C:\mzwu.txt", stream.ReadToEnd(), Encoding.Unicode);
MessageBox.Show(DateTime.Now.ToString() + ": 页面内容获取完成! ");
}
}
------解决方案--------------------
探讨
引用:

private void button1_Click(object sender, EventArgs e)
{
WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler……