我有一个程序,它使用 Jsoup 获取特定球队的曲棍球运动员的统计数据并将其放入单个字符串中。我想将线路分开,以便我可以在他们自己的字符串中获取每个玩家的统计数据。这是我拥有并解释的代码:
public static void main(String[] args) throws IOException {
Document doc = Jsoup.connect("http://espn.go.com/nhl/team/stats/_/name/phi/philadelphia-flyers").get();
for (Element table : doc.select("table.tablehead")) {
for (Element row : table.select("tr")) {
Elements tds = row.select("td");
if (tds.size() > 6) {
String a = tds.get(0).text() + ":" + tds.get(1).text() + " GOALS: " + tds.get(2).text() + " ASSISTS: " + tds.get(3).text() + " POINTS: " + tds.get(4).text() + " PLUS/MINUS: " + tds.get(5).text() + " PIM: " + tds.get(6).text();
System.out.println(a);
}
}
}
}
输出给出了多行,为了让您了解这些是它给出的前三行:
PLAYER:GP GOALS: G ASSISTS: A POINTS: PTS PLUS/MINUS: +/- PIM: PIM
Matt Read, C:13 GOALS: 5 ASSISTS: 4 POINTS: 9 PLUS/MINUS: 2 PIM: 2
Brayden Schenn, C:12 GOALS: 2 ASSISTS: 6 POINTS: 8 PLUS/MINUS: 3 PIM: 5
如果行的开头 = Matt Read 我想创建一个包含以下内容的字符串:
Matt Read, C:13 GOALS: 5 ASSISTS: 4 POINTS: 9 PLUS/MINUS: 2 PIM: 2
如果行的开头 = Brayden Schenn 我想创建一个包含以下内容的字符串:
Brayden Schenn, C:12 GOALS: 2 ASSISTS: 6 POINTS: 8 PLUS/MINUS: 3 PIM: 5