webbrowser 层层跳转的问题

胡椒csdn 胡椒csdn 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请教大神们个问题:
bool loading=true;
public void btn_Click(object sender, EventArgs e){
wb = new WebBrowser();
wb.DocumentCompleted += wb_DocumentCompleted;

wb.Navigate(url);
}
void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){
if (this.wb.ReadyState == WebBrowserReadyState.Complete) {
wb.DocumentCompleted -= wb_DocumentCompleted;
HtmlElementCollection collections = wb.Document.GetElementsByTagName("A");
wb.DocumentCompleted += detail_DocumentCompleted;
foreach (HtmlElement ele in collections) {
loading=true;
wb.Navigate(ele.GetAttribute("href"));
while(loading){
Application.DoEvents();
}
}
}
}

void detail_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
if (this.wb.ReadyState == WebBrowserReadyState.Complete) {
dosomething();
loading=false;
}
}
想实现通过层层跳转,跳转到目标页面,但是detail_DocumentCompleted事件不能被触发,如果把wb_DocumentCompleted里面的for循环去掉只navigate一次就可以触发detail_DocumentCompleted不知道是什么原因?希望大神们可以指点一下,
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
胡椒csdn
C# 111,130 成员 642,541 内容