How to get content from Windows Phone web control

I am trying to get a DOM model from web browser control or just HTML to process it using XML tools. This control does not offer any property that returns what I need. I found a solution using JS:

string html = Browser1.InvokeScript("eval", new string[] { "document.documentElement.outerHTML;" });

But I get an incomplete exception.

What am I doing wrong? I am new to WP programming.

+4
source share
1 answer

Like Romasz, use InvokeScriptAsync, but first make sure the page is loaded.

Application example:

<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)
        {
        }
    }

enter image description here

+9
source

All Articles