在 Jsoup 中使用 href 解析 table class 时遇到问题
Trouble parsing table class with href in Jsoup
我对 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>
我需要从上面提取主队、得分和客队,但是我目前遇到了问题。我需要 link 和文本本身。下面是我的代码:
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' 和它的所有其他变体。我设法获取了 'competition' class 中的数据,当我将 ("td[class=team.team=a]") 替换为 (td[class=competition]) 时,它会起作用,但是这不起作用不适用于任何具有 link.
的 classes
非常感谢您的帮助!
只需将多个类用点隔开:
td.team.team-a > a // first team
td.team.team-b > a // second team
td.score > a // score
我对 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>
我需要从上面提取主队、得分和客队,但是我目前遇到了问题。我需要 link 和文本本身。下面是我的代码:
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' 和它的所有其他变体。我设法获取了 'competition' class 中的数据,当我将 ("td[class=team.team=a]") 替换为 (td[class=competition]) 时,它会起作用,但是这不起作用不适用于任何具有 link.
的 classes非常感谢您的帮助!
只需将多个类用点隔开:
td.team.team-a > a // first team
td.team.team-b > a // second team
td.score > a // score