0

On Android.

I followed the steps on How do I get the web page contents from a WebView? When a page is loaded it logs out 'undefined' for document.

My SDK settings:

minSdkVersion 15
targetSdkVersion 22

code:

class JavaScriptInterface
{
    @JavascriptInterface
    public void processContent(String aContent)
    {
        Log.i("js", aContent);
    }
}

WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setUseWideViewPort(true);
myWebView.addJavascriptInterface(new JavaScriptInterface(), "INTERFACE");
myWebView.setWebViewClient(new WebViewClient() {

    @Override
    public void onPageFinished(WebView view, String url) {
        view.loadUrl("javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerHTML);");
    }
});
myWebView.loadUrl("http://example.com");
Community
  • 1
  • 1
Mymodo
  • 163
  • 1
  • 7
  • Try out JSOUP for Android – zgc7009 Jan 11 '16 at 17:17
  • @zgc7009 thanks for the tip, but this doesn't solve my problem since it would redownload the entire page. I need to parse the exact page that's loaded into my WebView. – Mymodo Jan 12 '16 at 09:13
  • 1
    You can use jsoup in conjunction with your WebView. Something like this http://stackoverflow.com/questions/26948087/parsing-logged-in-website-from-webview-with-jsoup should help if I understand your needs correctly. – zgc7009 Jan 12 '16 at 14:09

0 Answers0