![](/img/trans.png)
[英]Getting textbox values from a CefSharp browser using javascript
[英]Getting HTML from Cefsharp Browser
我在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.ViewSource()方法,以查看GetSourceAsync方法是否获取整个代码。
不幸的是,代码是不同的。 ViewSource正在获取整个代码,但是GetSourceAsync并未通过页面中生成的javascript获取代码。
Plase为我提供了一种获取页面源代码(如ViewSource)的方法,或者告诉我如何捕获此ViewSource方法的临时文件。
干杯。
试试这个,对我有用:
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 !
}
}
VB.Net:
Sub ShowSource()
Dim ts As task = getSource()
End Sub
Private Async Function getSource() As Task
Dim source As String = Await wb.GetBrowser().MainFrame.GetSourceAsync()
Dim f As String = Application.StartupPath + "/currentSource.txt"
Dim wr As StreamWriter = New StreamWriter(f, False, System.Text.Encoding.Default)
wr.Write(source)
wr.Close()
System.Diagnostics.Process.Start(f)
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.