Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从浏览器获取HTML_C#_Webbrowser Control_Chromium Embedded_Cefsharp - Fatal编程技术网

C# 从浏览器获取HTML

C# 从浏览器获取HTML,c#,webbrowser-control,chromium-embedded,cefsharp,C#,Webbrowser Control,Chromium Embedded,Cefsharp,我正在WinForm项目中使用CefSharp v55.0。加载页面后,我想从中获取HTML代码。为此,我用这个: private void WebBrowserFrameLoadEnded(object sender, FrameLoadEndEventArgs e) { if (e.Frame.IsMain) { test.ViewSource(); test.GetSourceAsync().ContinueWith(code =>

我正在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代码

请告诉我如何获取页面的源代码,如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 !
        }
    }
public void showSource()//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
看见