Reputation: 799
I am trying to use the CefSharp WPF package to load a web page then access the HTML source of the web page I have loaded.
I am able to display the web page correctly, but I want to be able to see the HTML of the page.
I am able to call the following, but it displays the text in a temporary text file, however I want to see the source as a string ideally but would be ok if the file saved to disk.
_webBrowser.ViewSourceCommand.Execute(this);
This is my class
public partial class View: Window
{
private CefSharp.Wpf.ChromiumWebBrowser _webBrowser;
public View()
{
InitializeComponent();
var settings = new CefSettings();
settings.PackLoadingDisabled = true;
_webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
BotBrowser.Children.Add(_webBrowser);
_webBrowser.Address = "http://www.google.com/";
}
private void button_Click(object sender, RoutedEventArgs e)
{
_webBrowser.ViewSourceCommand.Execute(this);
}
}
Upvotes: 2
Views: 5143
Reputation: 4420
Assuming your using the latest release version (43.0.1
) then use the GetSourceAsync()
method.
https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp/WebBrowserExtensions.cs#L158
ChromiumWebBrowser
implements the IWebBrowser
interface so you can use the extension method if you just want the source for the main frame.
Upvotes: 1