public async Task <IFrame> GetFrameAsync(ChromiumWebBrowser browser) { IFrame frame = null; var identifiers = browser.GetBrowser().GetFrameIdentifiers(); foreach (var i in identifiers) { frame = browser.GetBrowser().GetFrame(i); string source = await frame.GetSourceAsync(); Debug.WriteLine("NAME = " + frame); File.AppendAllText("C:/test/test4.txt", source); } return(null); }
public async Task <(string Document, string JumpUrl)> GetDocumentAsync(string url, Encoding encode) { _encoding = encode; _jumpUrl = ""; _document = ""; LoadUrlAsyncResponse loading = await _webBrowser.LoadUrlAsync(url); int waitedTime = 0; while (_webBrowser.IsLoading && !loading.Success) { Task.Delay(100).Wait(); waitedTime += 100; if (IsHandleCreated) { Invoke(new Action(() => txbMessage.AppendText($"网站未加载完, 等待1秒, Url={url}\r\n"))); } if (waitedTime > waitTime) { if (IsHandleCreated) { Invoke(new Action(() => txbMessage.AppendText($"等待时间超过{waitTime}, 强制返回\r\n"))); } break; } } IFrame frame = _webBrowser.GetMainFrame(); if (IsHandleCreated) { Invoke(new Action(() => txbMessage.AppendText($"Chrome浏览器网页加载完毕, 跳转Url={frame.Url}\r\n"))); } _jumpUrl = frame.Url; _document = await frame.GetSourceAsync(); return(_document, _jumpUrl); }