y70acom澳门银河:使用webbrowser和mshtml.dll获取网页源代码的问题

来源:百度文库 编辑:神马品牌网 时间:2024/04/19 07:27:01
我使用C#做一个程序,其中涉及到一个功能,在输入指定网址之后,需要获取html源代码进行分析。
我使用了webbrowser控件和mshtml.dll
但是只能获取到普通页面的源代码
一旦采集带有cookie控制的页面就会失败。
谁能帮帮忙?QQ:6477860

我对于webbrowser的使用并不很清楚,这个空间是否能直接获取html代码呢?
mshtml.dll说是可以对html代码进行分析。但如何使用?

有谁能给出说明和源代码,感激不尽。
我使用以下代码获取webbrowser中的html,但是有个很奇怪的问题。我每次点完按钮都会发现文本框中显示的html都不全,而且都把同一页面的html显示了很多遍。如果页面内容较大则会引起程序死掉。
为什么呢?

private void button1_Click(object sender, System.EventArgs e) {
object url=\"http://www.google.com\";
object nothing=null;
this.axWebBrowser1.Navigate2(ref url,ref nothing,ref nothing,ref nothing,ref nothing);
this.axWebBrowser1.DownloadComplete+=new System.EventHandler(this.button2_Click);
}

private void button2_Click(object sender, System.EventArgs e) {
this.textBox1.Text=\"\";
mshtml.IHTMLDocument2 doc=(mshtml.IHTMLDocument2)this.axWebBrowser1.Document;
mshtml.IHTMLElementCollection all=doc.all;
System.Collections.IEnumerator enumerator=all.GetEnumerator();
while(enumerator.MoveNext() && enumerator.Current!=null)
{
mshtml.IHTMLElement element=(mshtml.IHTMLElement)(enumerator.Current);
if(this.checkBox1.Checked==true)
{
this.textBox1.Text+=\"\\r\\n\\r\\n\"+element.innerHTML;
}
else
{
this.textBox1.Text+=\"\\r\\n\\r\\n\"+element.outerHTML;
}
}
}