我一直在移植我的Android应用程序。我的代码完好无损,但由于某种原因,JSoup似乎收到了错误的数据。我从工作的PC应用程序直接复制和粘贴,工作得很好。以下是一段代码,我使用的PC和Android的JSoup在Android上的行为与在PC上的行为不同?
String AllGamesURL = "http://www.nfl.com/standings?category=league&season=" + Stringyear + "-REG";
String HomeGamesURL = "http://www.nfl.com/standings?category=league&season=" + Stringyear + "-REG&split=Home";
String AwayGamesURL = "http://www.nfl.com/standings?category=league&season=" + Stringyear + "-REG&split=Road";
String DivisionGamesURL = "http://www.nfl.com/standings?category=league&season=" + Stringyear + "-REG&split=Division";
Document AllGames = Jsoup.connect(AllGamesURL).get();
Document HomeGames = Jsoup.connect(HomeGamesURL).get();
Document AwayGames = Jsoup.connect(AwayGamesURL).get();
Document DivisionGames = Jsoup.connect(DivisionGamesURL).get();
Elements AllGamesTeams = AllGames.select("table.data-table1 tr.tbdy1");
Elements HomeGamesTeams = HomeGames.select("table.data-table1 tr.tbdy1");
Elements AwayGamesTeams = AwayGames.select("table.data-table1 tr.tbdy1");
Elements DivisionGamesTeams = DivisionGames.select("table.data-table1 tr.tbdy1");
for (Element teamName : AllGamesTeams) {
if(teamName.select("td[align] > a[href]").text().trim().equals("")) {
team = teamName.select("td[align]").text().trim();
} else {
team = teamName.select("td[align] > a[href]").text().trim();
}
if(team.equals(currentSelectedTeam)) {
//Division = teamName.select("td:eq(2)").text().trim();
wins = Integer.parseInt(teamName.select("td:eq(3)").text().trim());
losses = Integer.parseInt(teamName.select("td:eq(4)").text().trim());
ties = Integer.parseInt(teamName.select("td:eq(5)").text().trim());
gamesPlayed = wins + losses + ties;
pointsFor = Integer.parseInt(teamName.select("td:eq(7)").text().trim());
pointsAgainst = Integer.parseInt(teamName.select("td:eq(8)").text().trim());
break;
}
}
在PC版本,它得到了胜,负,等得很好,但在Android上,这是得到错误的数据。有任何想法吗?
什么是“错”的呢? – chrylis
JSoup在PC版上获取正确的数据,但在Android版本上获取了错误的数据,即使读取该网站的代码是从PC版直接复制并粘贴的。 – user2581556
你只是重申你的文章,并没有回答我的问题。 – chrylis