bool loading = true; //该变量表示网页是否正在加载.
string html = string.Empty;
WebBrowser browser = new WebBrowser();
public void GetHtml(string[] urls)
{
browser.Navigated += new WebBrowserNavigatedEventHandler(browser_Navigated);
foreach (string url in urls)
{
loading = true; //表示正在加载
browser.Navigate(url);
while (loading)
{
Application.DoEvents();//等待本次加载完毕才执行下次循环.
}
}
}
void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
html = browser.DocumentText; //获取到的html.
loading = false;//在加载完成后,将该变量置为false,下一次循环随即开始执行.
}