1
private final Handler uiHandler = new Handler();
private class JSHtmlInterface {
    @android.webkit.JavascriptInterface
    public void showHTML(String html) {
        final String htmlContent = html;
        uiHandler.post(
            new Runnable() {
                @Override
                public void run() {
                    Document doc = Jsoup.parse(htmlContent);
                    Elements elements = doc.select("div[class='jsx-2839133444 main user-page']");
                    Log.e("asdasd", String.valueOf(elements));

                }
            }
        );
    }
}

try {
    browser.addJavascriptInterface(new JSHtmlInterface(), "JSBridge");
    browser.setWebViewClient(
        new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                progressDialog.show();
                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                browser.loadUrl("javascript:window.JSBridge.showHTML('<html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>');");
                progressDialog.dismiss();
            }
        }
    );
    browser.loadUrl("https://tiktok.com/@ronaldo");
} catch (Exception e) {
    e.printStackTrace();
}

enter image description here Hello everyone, I'm trying to parse the url using JSOUP with webview, but the required data is coming as - as in the picture. How can I solve it?

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
leonscot
  • 11
  • 2
  • Could you provide a sample HTML output you would like jsoup to extract from https://tiktok.com/@ronaldo ? – Janez Kuhar Oct 02 '21 at 11:13
  • Hello,
  • 552.1KFollowers
  • There should be a value between the strong tags, but it is empty as in my question above. – leonscot Oct 02 '21 at 11:34
  • Make sure to follow the example provided in the docs: [`public void addJavascriptInterface (Object object, String name)`](https://developer.android.com/reference/android/webkit/WebView#addJavascriptInterface(java.lang.Object,%20java.lang.String)) – Janez Kuhar Oct 02 '21 at 15:23
  • I think I made a mistake on the 'JavascriptInterface' side, but I still can't find it, can you help? – leonscot Oct 03 '21 at 07:34