locked
How to get HTML source information of WebView in Windows phone 8.1?

    Question

  • I want to get the HTML source information of the webpage ,and  when it go to other url can also get.I want to help,Thank.

    If you can provide an example would be better.

     
    Tuesday, December 23, 2014 2:58 AM

Answers

  • xaml

    <Page
        x:Class="GetHemlContentW81.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:GetHemlContentW81"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <WebView x:Name="webview" Source="http://google.com" DOMContentLoaded="WebView_DOMContentLoaded" />
        </Grid>
    </Page>

    C# code
    namespace GetHemlContentW81
    {
        /// <summary>
        /// An empty page that can be used on its own or navigated to within a Frame.
        /// </summary>
        public sealed partial class MainPage : Page
        {
            public MainPage()
            {
                this.InitializeComponent();
            }
    
            async private void WebView_DOMContentLoaded(WebView sender, WebViewDOMContentLoadedEventArgs args)
            {
                string html = await webview.InvokeScriptAsync("eval", new string[] { "document.documentElement.outerHTML;" });
                System.Diagnostics.Debug.WriteLine(html);
            }
        }
    }


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    Tuesday, December 23, 2014 8:50 AM