我是JSOUP的新手,只使用了几天,主要是从这个网站上学习。现在我想从下面的HTML中获取一些信息:
<td class="day no-repetition">Sun</td>
<td class="full-date" nowrap="nowrap">17/05/15</td>
<td class="competition"><a href="/national/england/premier-league/20142015/regular-season/r25191/" title="Premier League">PRL</a></td>
<td class="team team-a ">
<a href="/teams/england/sunderland-association-football-club/683/" title="Sunderland">
Sunderland
</a>
</td>
<td class="score-time score">
<a href="/matches/2015/05/16/england/premier-league/sunderland-association-football-club/leicester-city-fc/1704225/" class="result-draw">
0 - 0
</a>
</td>
<td class="team team-b ">
<a href="/teams/england/leicester-city-fc/682/" title="Leicester City">
Leicester City
</a>
</td>
<td class="events-button button first-occur">
</td>
<td class="info-button button">
<a href="/matches/2015/05/16/england/premier-league/sunderland-association-football-club/leicester-city-fc/1704225/" title="More info">More info</a>
</td>
我需要从上面提取主队,得分和客队,但我目前遇到问题。我需要链接和文本本身。以下是我的代码:
try {
Document doc = Jsoup.connect(URL).get();
Element table = doc.select("table[class=matches]").first();
Elements rows = table.select("tr");
for (int i=0; i<rows.size(); i++){
Element row = rows.get(i);
Elements data = row.select("td[class=team.team-a]");
System.out.println(data.text());
}
} catch (IOException e) {
e.printStackTrace();
}
到目前为止还没有奏效。我尝试了'team.team-a','team.team.a'以及它的所有其他变体。我设法得到了'竞争'类中的数据,当我用(td [class = competition])替换(“td [class = team.team = a]”)时,这个数据有效但是这不起作用任何有链接的类。
非常感谢协助!
答案 0 :(得分:2)
只需用点分隔多个类:
td.team.team-a > a // first team
td.team.team-b > a // second team
td.score > a // score