使用JSoup提取HTML表内容 [英] Using JSoup To Extract HTML Table Contents

查看:75
本文介绍了使用JSoup提取HTML表内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何提取位于以下位置的表的内容: /id/2/year/2012/acc-conference> http://espn.go.com/mens-college-basketball/conferences/standings//id/2/year/2012/acc-conference

How can I extract the contents of the table located at: /id/2/year/2012/acc-conference">http://espn.go.com/mens-college-basketball/conferences/standings//id/2/year/2012/acc-conference

我所看到的几个例子对于如何获取表的内容还不太清楚.谁能提供任何帮助?

The few examples I've seen aren't too clear on how to get the contents of the table. Can anyone offer any help?

推荐答案

您现在可能已经解决了这个问题,但这将遍历每个表并打印出团队名称和获胜/失败"列.调整所需的信息.第二张表的格式显然不同,因此,如果您想要与该表不同的信息,则必须进行进一步调整.让我知道您是否需要更多帮助.

You probably have this solved by now, but this will go over each table and print out the team name and the Win/Loss column. Adjust for the information you need. The second table is obviously formatted differently, so if you want different information from that table, you will have to adjust further. Let me know if you need any more help.

    Document doc = Jsoup.connect("http://espn.go.com/mens-college-basketball/conferences/standings/_/id/2/year/2012/acc-conference").get();

    for (Element table : doc.select("table.tablehead")) {
        for (Element row : table.select("tr")) {
            Elements tds = row.select("td");
            if (tds.size() > 6) {
                System.out.println(tds.get(0).text() + ":" + tds.get(1).text());
            }
        }
    }

这篇关于使用JSoup提取HTML表内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆