简体   繁体   中英

How to display only a table from a html file into a webview in Android

I would like to know how does one show only a table inside a webview by fetching it directly from the given url. Consider for example the url: http://www.soccerstats.com/ , in the right hand side we have several tables showing the played games and points, how do we do so for including only the table containing the details of Premier League in the webview. Otherwise, the only option parse each individual elements and then add one by one. Please help.

You can do it pretty easily with Jsoup . So your code would look something like this.

new AsyncTask<Void, Void, String>() {
    @Override
    protected String doInBackground(Void... params) {
        String data = null;
        try {
            Document doc = Jsoup.connect("http://wikipedia.com").get();
            data = doc.select("css_selector_here").html();
        } catch (Exception e) {
            e.printStackTrace();
        }
            return data;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        wv.loadData(s, "text/html", "UTF-8");
    }
}.execute();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM