简体   繁体   中英

How to extract the html code from webview to textview?

Its been a week since I start searching this question on the internet, But I cant get the solution.

I want to get the html code from webview and put it in a textview on android. I cant use jsoup connect because... I cant explain it too much, this is my example(example only)

On webview I have https://facebook.com(already login my fb account)

I cant use jsoup connect https://facebook.com because the html is On the fb login activity, I mean not login from facebook

I hope you understand

Create a load listener

class HTMLListener{
    public void processHTML(String html)
    {
        Log.e("output_html",html);
        // Then you can set your textview with html
    }
}

then in your webview config add this

webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new HTMLListener(), "LOADHTML");

then in webview client;

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
 
                return true;
        }              
       
        @Override
        public void onPageStarted(WebView view, String url,
                        Bitmap favicon) {
        }
       
        public void onPageFinished(WebView view, String url) {
            view.loadUrl("javascript:window.LOADHTML.processHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
        }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM