1.编写一个CefStringVisitor类:
public class MyStringVisitor : CefStringVisitor { private readonly TaskCompletionSource<string> taskCompletionSource; public MyStringVisitor() { taskCompletionSource = new TaskCompletionSource<string>(); } protected override void Visit(string value) { taskCompletionSource.SetResult(value); } public Task<string> Task { get { return taskCompletionSource.Task; } } }
2.在页面加载完成的事件中使用:
private static void OnWebBrowserFrameLoadEnd(object sender, FrameLoadEndEventArgs e) { MyStringVisitor taskStringVisitor = new MyStringVisitor(); e.Frame.GetSource(taskStringVisitor); string HTMLsource = taskStringVisitor.Task.Result; }
3.HTMLsource就是网页源代码内容。
原文地址:https://www.cnblogs.com/sinceret/p/11669217.html
时间: 2024-10-09 03:41:25