GetUrlDelegate2 getUrl = new GetUrlDelegate2(GetRequestDocument);
string[] aa = new string[] { "http://shanghai.baixing.com/ershouqiche/a94954831.html"
, "http://www.baidu.com/"
,"http://www.baidu.com/"
,"http://www.baidu.com/"
,"http://www.baidu.com/"
,"http://www.baidu.com/"
for (int i = 0; i < aa.Length; i++) {
getUrl(aa[i]);
}
void web_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
{
#region 加载完成事件
if (e.Url.ToString() == web.Url.ToString()) {
if (((WebBrowser)sender).ReadyState == WebBrowserReadyState.Complete)
{
string strCont = (sender as WebBrowser).Document.Body.OuterHtml;
IHTMLDocument2 doc2 = new HTMLDocumentClass();
doc2.designMode = "on";
doc2.write(new object[] { strCont });
doc2.close();
mshtml.HTMLDocument html = (doc2 as HTMLDocument);
GC.Collect();
this.textBox2.Text = strCont;
this.textBox1.Text = e.Url.ToString();
}
}
#endregion
}
执行时会漏连接,
注意:不用HttpWebRequest、WebRequest\WebClient,只用WebBrowser,
string[] aa = new string[] { "http://shanghai.baixing.com/ershouqiche/a94954831.html"
, "http://www.baidu.com/"
,"http://www.baidu.com/"
,"http://www.baidu.com/"
,"http://www.baidu.com/"
,"http://www.baidu.com/"
for (int i = 0; i < aa.Length; i++) {
getUrl(aa[i]);
}
void web_DocumentCompleted2(object sender, WebBrowserDocumentCompletedEventArgs e)
{
#region 加载完成事件
if (e.Url.ToString() == web.Url.ToString()) {
if (((WebBrowser)sender).ReadyState == WebBrowserReadyState.Complete)
{
string strCont = (sender as WebBrowser).Document.Body.OuterHtml;
IHTMLDocument2 doc2 = new HTMLDocumentClass();
doc2.designMode = "on";
doc2.write(new object[] { strCont });
doc2.close();
mshtml.HTMLDocument html = (doc2 as HTMLDocument);
GC.Collect();
this.textBox2.Text = strCont;
this.textBox1.Text = e.Url.ToString();
}
}
#endregion
}
执行时会漏连接,
注意:不用HttpWebRequest、WebRequest\WebClient,只用WebBrowser,
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货