Holen Sie sich den HTML-code aus CefSharp web-browser

Ich bin mit aCefSharp.Wpf.ChromiumWebBrowser (Version 47.0.3.0) zum laden einer web-Seite. Irgendwann, nachdem die Seite geladen wurde möchte ich an den Quelltext zu kommen.

Habe ich genannt:

wb.GetBrowser().MainFrame.GetSourceAsync()

jedoch erscheint es nicht wieder alle den source-code (ich glaube, das ist, weil es untergeordnete frames).

Wenn ich rufe:

wb.GetBrowser().MainFrame.ViewSource() 

Ich es sehen kann, sind alle source-code (einschließlich der inneren Bilder).

Ich würde gerne das gleiche Ergebnis erhalten wie ViewSource(). Könnte jemand mich in die richtige Richtung bitte?

Update – Added-Code-Beispiel

Hinweis: Die Adresse der web-browser zeigt auch das wird nur funktionieren, bis zu und einschließlich 10/03/2016. Danach darf die Anzeige verschiedener Daten, die nicht ist, was würde mich der Suche an.

In der frmSelection.xaml-Datei

<cefSharp:ChromiumWebBrowser Name="wb" Grid.Column="1" Grid.Row="0" />

In der frmSelection.xaml.cs-Datei

public partial class frmSelection : UserControl
{
    private System.Windows.Threading.DispatcherTimer wbTimer = new System.Windows.Threading.DispatcherTimer();

    public frmSelection()
    {

         InitializeComponent();

         //This timer will start when a web page has been loaded.
         //It will wait 4 seconds and then call wbTimer_Tick which 
         //will then see if data can be extracted from the web page.
         wbTimer.Interval = new TimeSpan(0, 0, 4);
         wbTimer.Tick += new EventHandler(wbTimer_Tick);

         wb.Address = "http://www.racingpost.com/horses2/cards/card.sd?race_id=644222&r_date=2016-03-10#raceTabs=sc_";

         wb.FrameLoadEnd += new EventHandler<CefSharp.FrameLoadEndEventArgs>(wb_FrameLoadEnd);

    }

        void wb_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
        {
            if (wbTimer.IsEnabled)
                wbTimer.Stop();

            wbTimer.Start();
        }

    void wbTimer_Tick(object sender, EventArgs e)
    {
        wbTimer.Stop();
        string html = GetHTMLFromWebBrowser();
    }

    private string GetHTMLFromWebBrowser()
    {
         //call the ViewSource method which will open up notepad and display the html.
         //this is just so I can compare it to the html returned in GetSourceAsync()
         //This is displaying all the html code (including child frames)
            wb.GetBrowser().MainFrame.ViewSource();

         //Get the html source code from the main Frame.
            //This is displaying only code in the main frame and not any child frames of it.
            Task<String> taskHtml = wb.GetBrowser().MainFrame.GetSourceAsync();

            string response = taskHtml.Result;
     return response;
  }

}
  • Kannst du etwas mehr code? Ich kann nicht Ihr problem reproduzieren, habe ich den gleichen text mit GetSourceAsync als mit ViewSource. Habe es versucht mit Address eingestellt http://stackoverflow.com (es hat zwei frames, eine iframe - und Haupt-frame)
  • Vielen Dank für das ansehen. Ich habe Hinzugefügt, beispielsweise source-zu dem original-Beitrag.
InformationsquelleAutor Scott | 2016-03-09
Schreibe einen Kommentar