How I get page source from WebView?

get page source from url android
how to get data from webview in android
get text from webview android
android webview evaluatejavascript
extracting html from a webview
android webview browser
android chrome webview example
android webview settings

How I get the web page's source from WebView?

I want to only enter www.google.com in my webview and When I entered this site, I want to get the source for example

String a=........;(source) 

I am not sure how far this is going to be helpful. But I have used the below snippet to fetch a small html page's data. I hope it helps you.

Create a class like the one below,

  class MyJavaScriptInterface
  {
      @SuppressWarnings("unused")
      public void processHTML(final String html)
      {
          Log.i("processed html",html);

            Thread OauthFetcher=new Thread(new Runnable() { 

                @Override
                public void run() {

                    String oAuthDetails=null;
                      oAuthDetails=Html.fromHtml(html).toString();
                      Log.i("oAuthDetails",oAuthDetails);

                }
            });OauthFetcher.start();
        }
      } 

Now in your onCreate(),

 webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");

     webview.setWebViewClient(new WebViewClient(){

            @Override
            public void onPageFinished(WebView view, final String url) {


                String oAuthUrl=getString("www.google.com");

                if(url.contains(oAuthUrl))
                {
                    Log.i("Contains","Auth URL");

                    twitter_webview.loadUrl("javascript:window.HTMLOUT.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
                }
            }
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

                progressDialog.show();
            }
      });

And now what happens is that, when your page finishes loading, the JavaScript class will be called, which would retrieve the page source and store it in a String as your requirement.

Getting the HTML source from an Android WebView, The feed reader is using an Android WebView to display the contents of a some issues I had I wanted to be able to view the HTML source for a page. But no, there's no method to get the HTML source from a WebView,� Choose the Show page source option. Opera users. To view the source code of a web page in Opera, follow the steps below. Press Ctrl+U on your keyboard. Or. Right-click on a blank part of the web page and select Page source from the pop-up menu that appears. Or. Open Opera and navigate to the web page of your choice.

And For API 17

import android.webkit.JavascriptInterface;

public class MainActivity extends Activity {

final Context myApp = this;

@JavascriptInterface
public void processHTML(String html) {
    if (html == null)
        return;

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WebView browser = (WebView) findViewById(R.id.webview);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.addJavascriptInterface(this, "HTMLOUT");
    browser.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            browser.loadUrl("javascript:window.HTMLOUT.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
        }
    });
    browser.loadUrl("http://www.google.co.il");
}

}

Building web apps in WebView, View and download the HTML source code of any online web page on your mobile. This tool works on any browser, tablet, laptop, Android, or Apple iOS device. Is there any way to get the html page that is shown in the WebView at some moment of time ? I want to get this html page as string variable. The point is I want to get the html code after the javascript is executed on a client side

If your minSdkVersion is 19 or greater you can use the following.

override fun onPageFinished(view: WebView?, url: String?) {
    super.onPageFinished(view, url)
    view?.evaluateJavascript("""(function() {
        return "<html>" + document.getElementsByTagName('html')[0].innerHTML + "</html>";
    })()""".trimMargin()) {
        console.log(it)
    }
}

View Page Source, Android webview get source. Getting the HTML source from an Android WebView , setWebViewClient(new WebViewClient(){ @Override public void� Using webview.loadUrl(url) method I open an url. If I click any Button on the view it directs to another page. Now I want to get the url of the directed page. how can I get it? I also want the con

How to get the HTML source of a page from a HTML link in Android?, To display a website from the internet, set the WebView 's Source iOS { public class BaseUrl_iOS : IBaseUrl { public string Get() { return� How I get the web page's source from WebView? I want to only enter www.google.com in my webview and When I entered this site, I want to get the source for example

Xamarin.Forms WebView, In Firefox or Chrome on Android it's possible to view source by prefixing the URL in the Now when on a page, tap the address field and start typing: vs. Change the user agent to Android and you get the mobile version of the site, but with� The object passed to source can have either of the following shapes: Load uri. uri (string) - The URI to load in the WebView. Can be a local or remote file. method (string) - The HTTP Method to use. Defaults to GET if not specified. On Android, the only supported methods are GET and POST. headers (object) - Additional HTTP headers to send with

How do I view source in the Android browser?, How I get the web page's source from WebView? I want to only enter www. google.com in my webview and When I entered this site, I want to get� My interpretation of this question is: How can i get the HTML from a web page, such that i can reload it and have it function EXACTLY the same. This accepted answer does NOT answer this question. At least in my app, the testing reveals no clickable links despite the page showing properly. I currently have no lead about how to save the HTML and

Comments
  • Do you want the whole source code or just the HTML tags?
  • I want to whole source code . (for example when I paste it in .txt and open it with browser I want to see the site )
  • Yes I do and I have submitted an edit and I am now flagging this as a exact duplicate of stackoverflow.com/questions/4543663/…
  • I m sorry.I do not Understand really.What you mean addJavascriptInterface(). it is static where can ı find this
  • Bitmap and progressDialogit does not seen and does not import,I change twitter_webview to webvie ? what can ı do
  • isn't that the question is all about? To fetch the page source? That's why I read the page source as a String and store it..
  • sorry. Got your question wrong. The thread is to avoid any interference to the Main UI thread. if the web page, then to download its content into a string will take a long time. If we dont do this in a secondary thread, then the main thread gets blocked and you might get ANR dialog.