使用 JSoup 提取 HTML 表格内容

发布于 2024-12-17 11:41:46 字数 193 浏览 2 评论 0原文

如何提取位于以下位置的表的内容: /id/2/year/2012/acc-conference">http://espn.go.com/mens-college-basketball/conferences/stands//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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城泪 2024-12-24 11:41:46

您现在可能已经解决了这个问题,但这将遍历每个表格并打印出团队名称和赢/输列。调整您需要的信息。第二个表的格式显然不同,因此如果您想要该表中的不同信息,则必须进一步调整。如果您需要更多帮助,请告诉我。

    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());
            }
        }
    }

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());
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文