【问题标题】:Volley android remove div-container from fetched jsonVolley android从获取的json中删除div-container
【发布时间】:2017-05-25 21:15:03
【问题描述】:

我使用 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>

我想在我的应用中显示全文,所以应该删除整个 -part。除了为每篇文章(id,这里是 345)构建字符串之外,还有更好的方法吗?我虽然也许我可以使用 volley 来“过滤”掉 div,但还没有弄清楚如何。

【问题讨论】:

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


    【解决方案1】:

    如果我明白了,你想从带有 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");
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多