基于WebBrowser 的爬虫程序
2021-07-09 00:04
标签:ref 加载 nbsp 获取 app text lan bool foreach 基于WebBrowser 的爬虫程序 标签:ref 加载 nbsp 获取 app text lan bool foreach 原文地址:http://www.cnblogs.com/ransom/p/7095880.html
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,下一次循环随即开始执行.
}