c# - Web浏览器页面循环加载

标签 c#

好吧,这个问题我已经找了一整天了。我有一个循环,在其中加载网页并解析它们。

问题是 Application.DoEvents 和 while 循环重置每个变量和计数器 Thread.Sleep() 影响加载网页的线程 AutoResetEvent.WaitOne 也是如此

这是我的代码

private void button1_Click_1(object sender, EventArgs e)
{
//some code...
for (int i = 1; i < div.Children.Count; i++)
        {
            webview.Navigate(addr);
            //wait until page is loaded
            html_code.Text += "OK!"; //do further actions
        }
}

您注意到我有一个 for 循环,因此上面列出的所有方法都不起作用。我请求你帮我解决我的问题

更新:我找到了解决方案。此处描述 https://stackoverflow.com/a/4271581/1894634

最佳答案

如果您只需要 html 响应,最好使用 WebClient.DownloadStringWebClient.DownloadStringAsync 方法

WebClient client = new WebClient ();
//client.Credentials = new NetworkCredential(username, password);
string html_code = client.DownloadString (addr);

关于c# - Web浏览器页面循环加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14032292/

相关文章:

c# - 显示/隐藏 Crystal 报表中某些记录的数据字段和标签

c# - 托管环境中的多线程 Pinvoked DLL。是否可以?

c# - 如何将 getter 和 setter 添加到 PropertyDeclarationSyntax?

c# - wp7 上的折线图

c# - 什么 WPF C# 控件类似于 C++ 中的 CWnd?

c# - 如何在powerpoint中添加项目符号

c# - 如何获取故障转储

c# - 为什么通过 Latest 订阅 RX.NET 中的可观察对象只接受 1 个订阅者?

c# - 使用 Android 模拟器从外部应用程序通过 COM 测试 AT 命令

c# - 对于带有 QueueTrigger 的 Azure WebJob,设置计划有什么影响吗?