使用CEFSHARP函数GetSourCeasync()时,源代码与ChatsIndionOurce()相比
我已经安装了最新版本的CEFSHARP,当我调用Viewsource()时,它将打开带有源代码的记事本窗口。但是,当我调用getSourCeasync()时,代码非常不同,并且缺少我在记事本窗口中显示的 var html 中所需的html。唯一的工作是以某种方式将记事本中的代码内容复制到我的应用中并使用它。有人知道如何像记事本窗口中所示获取HTML吗?我正在使用Visual Studio 2017 Express在Windows 7 Pro操作系统中运行该应用程序。这是我的代码...
private void WebBrowserFrameLoadEndedAsync(object sender, FrameLoadEndEventArgs e)
{
chromeBrowser.ViewSource();
chromeBrowser.GetSourceAsync().ContinueWith(taskHtml =>
{
var html = taskHtml.Result;
});
}
}
Here is the web page that the browser goes to...
chromeBrowser = new ChromiumWebBrowser("https://www.amazon.com/product-reviews/B084RCFDJ3/ref=acr_search_hist_5?ie=UTF8&filterByStar=five_star&reviewerType=all_reviews#reviews-filter-bar");
I have the latest version of CefSharp installed and when I call ViewSource(), it opens up a notepad window with the source code. But when I call GetSourceAsync() the code is very different and missing the HTML I need in the var html that is shown in the Notepad window. The only work around would be to somehow copy the contents of the code in Notepad into my app and use it. Does anyone know how to get the html as shown in the NotePad window? I'm running the application in the Windows 7 Pro operating system using Visual Studio 2017 Express. Here is my code...
private void WebBrowserFrameLoadEndedAsync(object sender, FrameLoadEndEventArgs e)
{
chromeBrowser.ViewSource();
chromeBrowser.GetSourceAsync().ContinueWith(taskHtml =>
{
var html = taskHtml.Result;
});
}
}
Here is the web page that the browser goes to...
chromeBrowser = new ChromiumWebBrowser("https://www.amazon.com/product-reviews/B084RCFDJ3/ref=acr_search_hist_5?ie=UTF8&filterByStar=five_star&reviewerType=all_reviews#reviews-filter-bar");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,我正在搜索错误的短语。所以现在我只打电话以下...
It turns out, I was searching the source for the wrong phrase. So now I just call the following...
我已经详细介绍了GetSource和ViewSource之间的区别。
有关
FrameloDadend
的一些重要事情。说明行为差异的说明
首先
viewsource()
立即返回,Notepad
在getsourCeasync
call具有完全的。这两种方法都将
getsource
消息发送到渲染过程,该过程返回readonlysharedMemoryRegion
。当您从共享内存部分中阅读数据时,及时会带有不同的快照。cefframeHostimpl :: getsource
方法getsourCeasync
呼叫完成非常快速完成,因为它只是从共享存储器部分创建字符串。cefframeHostimpl :: viewsource
方法立即返回要慢得多,并且需要其他处理来在磁盘上创建文件,请写下该字符串,Spawn Notepad。HTML源始终是给定时间点的来源的快照。对于静态网页,时间没有区别,对于动态渲染/更新的网站,几百毫秒可能意味着您获得了完全不同的来源。
当共享
ReadOnlySharedMemoryRegion
转换为字符串时,意味着您最终获得的源有细微的差异。I've gone into detail on the difference between GetSource and ViewSource further down.
Some important things to note about
FrameLoadEnd
.Explanation of the difference in behaviour
Firstly
ViewSource()
returns immediately,Notepad
is being launched after theGetSourceAsync
call has completed.Both methods send a
GetSource
message to the render process which returns aReadOnlySharedMemoryRegion
. When you read the data from the shared memory section ends up with a different snapshot in time.CEF Source reference.
The
CefFrameHostImpl::GetSource
method whichGetSourceAsync
calls completes very quickly as it simply creates a string from the shared memory section.The
CefFrameHostImpl::ViewSource
method whilst returns immediately is much slower and takes additional processing to create a file on disk, write that string, spawn notepad.HTML Source is always a snapshot of source for a given point in time. For static web pages, time makes no difference, for dynamically rendered/updated websites a few hundred milliseconds can mean you get entirely different source.
When the shared
ReadOnlySharedMemoryRegion
is converted into a string means there is a subtle difference in the source you end up getting.