Volley android从抓取的json中删除div-container

时间:2017-05-25 21:15:04

标签: android wordpress rest android-volley wordpress-rest-api

我使用volley通过它的api从wordpress博客中获取内容。

我收到的内容如下:

<p>Blog content blabla</p>\n
<div id=\ "pressrelease-link-345\"  class=\ "sh-link pressrelease-link sh-hide\">
  <a href=\ "#\" onclick=\ "showhide_toggle('pressrelease', 345, 'Show full article', 'Hide article'); return false;\" aria-expanded=\ "false\">
    <span id=\"pressrelease-toggle-345\">Show full article</span>
  </a>
</div>
<div id=\ "pressrelease-content-345\" class=\ "sh-content pressrelease-content sh-hide\" style=\ "display: none;\">
  </p>\n
  <p>more content which is displayed after expanding the text in the browser</p>

我想在我的应用中显示全文,因此应删除整个部分。有没有比为每篇文章构建字符串更好的方法(id,这里345)?我想也许我可以过滤&#39;使用凌空抽出div,但还没有弄明白。

1 个答案:

答案 0 :(得分:0)

如果我理解,你想从带有WebView的HTML页面中删除div?

private void yourwebv (){
    String url = "mysite.com";
    final WebView webview = (WebView) findViewById(R.id.WEBVIEW_ID);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebChromeClient(new WebChromeClient());

    webview.setVisibility(View.INVISIBLE);
    final ProgressBar ProgressBar = (ProgressBar) findViewById(R.id.ProgressBar);
    ProgressBar.setVisibility(View.VISIBLE);


    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url){
            String javaScript ="javascript:document.getElementsByClassName('YOURDIVCLASSNAME_REMOVE')[0]" +
                    ".style.display='none';void(0);";
            webview.loadUrl(javaScript);
            Log.d("[WV]", " JS OK");

            final ProgressBar ProgressBar = (ProgressBar) findViewById(R.id.ProgressBar);
            ProgressBar.setVisibility(View.INVISIBLE);
            webview.setVisibility(View.VISIBLE);
        }
    });
    webview.loadUrl(url);
    Log.d("[WV]", " WEBSITE + JS SCRIPT OK");
}