我可以获取Metro WebView控件的当前HTML或Uri吗? [英] Can I get the current HTML or Uri for the Metro WebView control?

查看:41
本文介绍了我可以获取Metro WebView控件的当前HTML或Uri吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在WebView中导航时,似乎没有更新XAML WebView控件的Source属性.是否可以获取当前Uri或WebView中当前呈现的HTML?我需要解析正在显示的HTML,以便两者都能工作.

It doesn't appear that the Source property for the XAML WebView control is updating as the user is navigating in the WebView. Is it possible to get either the current Uri or the HTML currently being rendered in the WebView? My need is to parse the HTML that is being displayed so either would work.

推荐答案

结果证明,WebView没有提供直接检索其HTML的方法.但是您可以像这样使用WebView.InvokeScript:

Turns out that the WebView doesn't provide a way to retrieve its HTML directly. But you can use WebView.InvokeScript like this:

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

您还可以通过LoadCompleted事件的NavigationEventArgs.Uri获取Uri.

You can also obtain the Uri via the LoadCompleted event's NavigationEventArgs.Uri.

这篇关于我可以获取Metro WebView控件的当前HTML或Uri吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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