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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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;"})
You can also obtain the Uri via the LoadCompleted event's NavigationEventArgs.Uri.
回答2:
Did you look at the LoadCompleted event for WebView? That gives the URI that's just loaded.
回答3:
The property you are looking for is called Source
.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.webview.source.aspx
Unluckily the Document
property of WinForms WebBrowser
doesn't seem to exist anymore.
You will have to re-download the page and process it using libraries like HtmlAgilityPack and Fizzler/FizzlerEx.