C#WebView2 Waithandle序列化几页的加载
伙计们。我想通过WebView2从几页中抓取数据。我将要一一从页面中加载和提取数据。我编写了一些代码,但它们没有起作用。我被困。这是核心代码:
async Task Crawl()
{
AutoResetEvent loadEvent = new AutoResetEvent(false);
wv2.NavigationCompleted += Wv2_NavigationCompleted;
foreach (var url in urls)
{
wv2.Source = new Uri(url);
loadEvent.WaitOne();
var data = await ExtractData();
...
}
wv2.NavigationCompleted -= Wv2_NavigationCompleted;
void Wv2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
loadEvent.Set();
}
}
folks. I want to crawl data from a few pages with webview2. I am about to load and extract data from the pages one by one. I wrote some codes but they didn't work. I am stuck. Here are the core codes:
async Task Crawl()
{
AutoResetEvent loadEvent = new AutoResetEvent(false);
wv2.NavigationCompleted += Wv2_NavigationCompleted;
foreach (var url in urls)
{
wv2.Source = new Uri(url);
loadEvent.WaitOne();
var data = await ExtractData();
...
}
wv2.NavigationCompleted -= Wv2_NavigationCompleted;
void Wv2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
{
loadEvent.Set();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论