0

Assume that I have a web-page named abc.html as follows:

<!DOCTYPE html>
<body>

<div class="a"><p>Only display this</p></div>
<div class="b"><p>Don't display this</p></div>
<div class="c"><p>Don't display this</p></div>

</body></html>

Can you please give me any idea how can I display only the <div class="a"> in android webview.

Here is my code to load full web-page

public class CustomWebsite extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_website); 

        webView = (WebView) findViewById(R.id.webView_test);
        webView.setWebViewClient(new myWebClient());
        webView.getSettings().setJavaScriptEnabled(true); 
        webView.loadUrl("http://skyasim.info/abc.html");

        }

          public class myWebClient extends WebViewClient
            {
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    // TODO Auto-generated method stub
                    super.onPageStarted(view, url, favicon);
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    // TODO Auto-generated method stub

                    view.loadUrl(url);
                    return true;

                }
            }           

    }
4

1 回答 1

0

您可以注入自己的 JS 来摆脱/隐藏其他元素。jQuery 示例:

$("div:not(.a)").remove();

Presto, divs 除了任何类a都将从 DOM 树中删除。

否则,如果你愿意,你可以自己获取数据,自己寻找并销毁所有div不是类的 sa并将字符串加载到 webview 中。

于 2013-08-02T21:08:21.890 回答