我在我的 WinForm 项目中使用 CefSharp v55.0。页面加载后,我想从中获取 HTML 代码。为此,我正在使用这个:
private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e)
{
if (e.Frame.IsMain)
{
test.ViewSource();
test.GetSourceAsync().ContinueWith(code =>
{
var html = code.Result;
});
}
}
对于交叉检查,我还调用 test.View Source() 方法,以查看 GetSource Async 方法是否获取整个代码。
不幸的是,代码不同。 View Source 正在获取整个代码,但 GetSource Async 并未通过页面中生成的 javascript 获取代码。
请引导我一种获取页面源代码(例如“查看源代码”)的方法,或者告诉我如何捕获此“查看源代码”方法临时文件。
Cheers.
试试这个,它对我有用:
public void showSource() // <<<<<<<<<<<<<<<<<<<<<<<<<< Call this function
{
Task ts = getSource();
}
private async Task getSource()
{
try
{
//
string source = await chromeBrowser.GetBrowser().MainFrame.GetSourceAsync();
//
string f = Application.StartupPath + "\\currentSource.txt";
//
StreamWriter wr = new StreamWriter(f, false, System.Text.Encoding.Default);
wr.Write(source);
wr.Close();
//
System.Diagnostics.Process.Start(f);
//
}
catch (Exception)
{
//Error !
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)