0

I know this question has already been asked before but the solutions doesn't work or are deprecated..

So, I want get the html code of a webpage in android in java, if somebody can help me..

techraf
  • 64,883
  • 27
  • 193
  • 198
R3J3CT3D
  • 226
  • 2
  • 10
  • You can read about [HttpURLConnection](https://developer.android.com/reference/java/net/HttpURLConnection.html) and use that instead of the deprecated `DefaultHttpClient` in the examples. The changes required are quite small. Learning to use [Volley](https://developer.android.com/training/volley/index.html) for network operations is also a good idea. And [jsoup](https://jsoup.org/) is also an option and it also helps in parsing the HTML "DOM tree" if that's necessary. – Markus Kauppinen Oct 20 '16 at 16:05
  • There's the URL scheme `view-source:[insert webpage here]` that makes browsers display the HTML source of the webpage instead of rendering it. Have you tried that scheme? – The SE I loved is dead Oct 20 '16 at 19:12

1 Answers1

0

use webview to load url in your app then use the following code to get the html

wvbrowser.evaluateJavascript(
        "(function() { return ('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>'); })();",
         new ValueCallback<String>() {
            @Override
            public void onReceiveValue(String html) {
                Log.d("HTML", html); 
                // code here
            }
    });

taken from

Community
  • 1
  • 1
Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89