I am trying to get a DOM model from webview control or just HTML to process it by XML tools. That control does not offer any property which returns what I need. I have found a solution by using JS:
string html = Browser1.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" });
But I am getting a not implemented exception.
What am I doing wrong? I'm new in WP programming.
Like Romasz said use InvokeScriptAsync -- but make sure the page is loaded first.
Sample Application:
<Grid>
<StackPanel>
<WebView x:Name="myWebView" Height="300" VerticalAlignment="Top" />
<Button Content="Read HTML" Click="Button_Click" />
<TextBlock x:Name="myTextBlock"></TextBlock>
</StackPanel>
</Grid>
private void Page_Loaded(object sender, RoutedEventArgs e)
{
this.myWebView.Navigate(new Uri("http://www.google.com", UriKind.Absolute));
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
string html = await myWebView.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
myTextBlock.Text = html;
}
catch (Exception ex)
{
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With