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

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

问题描述

当用户在 WebView 中导航时,XAML WebView 控件的 Source 属性似乎没有更新.是否可以获取当前在 WebView 中呈现的 Uri 或 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天全站免登陆