我需要ChromiumWebBrowser将所有页面加载为URL数组,在每个页面上执行javascript,然后下载其源代码。我编写了以下代码:
ChromiumWebBrowser[] chromium = new ChromiumWebBrowser[offersLinks.Count()];
for(int i = 0; i < offersLinks.Count(); ++i)
{
Debug.WriteLine("Page " + (i + 1) + "/" + offersLinks.Count());
chromium[i] = new ChromiumWebBrowser(offersLinks[i]);
chromium[i].FrameLoadEnd += async (sender, args) =>
{
//Wait for the MainFrame to finish loading
if (args.Frame.IsMain)
{
Debug.WriteLine("Loaded.");
if (chromium[i].CanExecuteJavascriptInMainFrame)
{
JavascriptResponse response = await chromium[i].EvaluateScriptAsync(javascript);
if (response.Result != null)
{
Debug.WriteLine(response.Message);
}
}
chromium[i].ViewSource();
string html = await chromium[i].GetSourceAsync();
}
};
}
但是,由于某种原因,FrameLoadEnd回调中的代码永远不会执行。你能给我解释一下吗?