如何从 Windows Phone webview 控件获取内容 [英] How to get a content from Windows Phone webview control

查看:30
本文介绍了如何从 Windows Phone webview 控件获取内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 webview 控件或 HTML 中获取 DOM 模型,以便通过 XML 工具对其进行处理.该控件不提供任何返回我需要的属性.我通过使用 JS 找到了一个解决方案:

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.

我做错了什么?我是 WP 编程的新手.

What am I doing wrong? I'm new in WP programming.

推荐答案

就像 Romasz 所说的使用 InvokeScriptAsync —— 但要确保页面首先被加载.

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

示例应用:

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

<小时>

这篇关于如何从 Windows Phone webview 控件获取内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆