简体   繁体   English

如何在Android中仅显示从html文件到Webview的表格

[英]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. 我想知道如何通过直接从给定的url中获取表格来仅显示webview中的表格。 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. 例如,考虑以下网址: http : //www.soccerstats.com/ ,我们在右侧有几个表格,显示了玩过的游戏和得分,我们如何做到这一点,因为只包括了包含英超联赛详细信息的表格网络视图。 Otherwise, the only option parse each individual elements and then add one by one. 否则,唯一的选项将解析每个单独的元素,然后一个一个地添加。 Please help. 请帮忙。

You can do it pretty easily with Jsoup . 您可以使用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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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