0

I want to get html source code in c# (mono for android)

I add webview in my project. webview name is web.

my code:

WebView webView;
protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);    webView.Settings.JavaScriptEnabled = true;
            webView.Settings.SetSupportZoom(true);
            webView.Settings.BuiltInZoomControls = true;
            webView.Settings.LoadWithOverviewMode = true; //Load 100% zoomed out
            webView.ScrollBarStyle = ScrollbarStyles.OutsideOverlay;
            webView.ScrollbarFadingEnabled = true;


            webView.VerticalScrollBarEnabled = true;
            webView.HorizontalScrollBarEnabled = true;

            webView.SetWebViewClient(new AwesomeWebClient());
            webView.SetWebChromeClient(new AwesomeWebChromeClient(this));
            webView.LoadUrl(@"http://www.google.com");
        }
    private class AwesomeWebClient : WebViewClient { }

    private class AwesomeWebChromeClient : WebChromeClient
    {
        private Activity mParentActivity;
        private string mTitle;
        private string username;
        private string password;
        private string oldurl="";

        public AwesomeWebChromeClient(Activity parentActivity)
        {
            mParentActivity = parentActivity;
            mTitle = parentActivity.Title;
        }


        public override void OnProgressChanged(WebView view, int newProgress)
        {
            mParentActivity.Title = string.Format("Loading {0}%", newProgress);
            mParentActivity.SetProgress(newProgress * 100);
            if (newProgress==100) mParentActivity.Title=mTitle;
        }
    }

I open www.google.com in webview component and I want to see html source code

durron597
  • 31,968
  • 17
  • 99
  • 158

1 Answers1

1

I don't believe that there is a way to obtain the HTML from the WebView.

Instead, you should grab the HTML yourself with a WebRequest, e.g. this handy StackOverflow answer.

Community
  • 1
  • 1
jonp
  • 13,512
  • 5
  • 45
  • 60