我使用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,但还没有弄明白。
答案 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");
}