【问题标题】:Using JSoup To Extract HTML Table Contents使用 JSoup 提取 HTML 表格内容
【发布时间】:2012-01-03 13:26:50
【问题描述】:

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

我见过的几个例子对如何获取表格的内容不太清楚。任何人都可以提供任何帮助吗?

【问题讨论】:

  • http://espn.go.com/mens-college-basketball/conferences/standings//id/2/year/2012/acc-conference 返回 404 未找到错误:The URL you requested does not exist, but you may be interested in the content below。你确定它是正确的网址吗?

标签: jsoup


【解决方案1】:

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

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

【讨论】:

  • ElementsElement 的拼写错误
猜你喜欢
  • 2013-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多