日期:2014-05-18 浏览次数:20933 次
private void btn_Click(object sender, EventArgs e) { string url = "http://www.aastocks.com/SC/Stock/CompanyFundamental.aspx?CFType=8&symbol="; string[] stra = new string[5]; stra[0] = url+"00001"; stra[1] = url+"00002"; stra[2] = url+"00003"; stra[3] = url+"00004"; stra[4] = url+"00005"; GetHtml(stra); } bool loading = true; //该变量表示网页是否正在加载. string html = string.Empty; //WebBrowser browser = new WebBrowser(); public void GetHtml(string[] urls) { this.webBrowser1.Navigated += new WebBrowserNavigatedEventHandler(browser_Navigated); foreach (string url in urls) { loading = true; //表示正在加载 webBrowser1.Navigate(url); while (loading) { Application.DoEvents();//等待本次加载完毕才执行下次循环. } } } void browser_Navigated(object sender, WebBrowserNavigatedEventArgs e) { html = webBrowser1.DocumentText; //获取到的html. loading = false;//在加载完成后,将该变量置为false,下一次循环随即开始执行. }