Android 带JSOUP问题的刮表
我正在使用JSOUP从包含玩家名称和统计信息的站点上的表中提取数据。我能够成功地获得这个名字,但是当我运行我的迭代程序时,它总是为每个球员获得相同的数据 有什么想法吗 网站来源:Android 带JSOUP问题的刮表,android,iterator,web-scraping,jsoup,Android,Iterator,Web Scraping,Jsoup,我正在使用JSOUP从包含玩家名称和统计信息的站点上的表中提取数据。我能够成功地获得这个名字,但是当我运行我的迭代程序时,它总是为每个球员获得相同的数据 有什么想法吗 网站来源: <tr id="plyr22" class="pncPlayerRow playerTableBgRow0"><td class="playertableData">1</td><td class="playertablePlayerName" id="playername_2
<tr id="plyr22" class="pncPlayerRow playerTableBgRow0"><td class="playertableData">1</td><td class="playertablePlayerName" id="playername_22" style=""><a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="null" leagueId="0" playerId="22" teamId="-2147483648" cache="true">Kobe Bryant</a>, LAL SG<a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="1" leagueId="0" playerId="22" teamId="-2147483648" cache="true"><img src="http://g.espncdn.com/s/fbalm/12/images/icons/sml/news_recent.png" height="12" width="15" border="0" style="margin:0 6px 0 6px" title="Recent News" /></a></td><td class="sectionLeadingSpacer"></td><td class="playertableData">0.63</td><td class="playertableData">2.41</td><td class="playertableData">1.44</td><td class="playertableData">1.29</td><td class="playertableData">2.82</td><td class="playertableData">1.84</td><td class="playertableData">0.18</td><td class="playertableData">4.81</td><td class="playerTableSpacerCell"></td><td class="playertableData sortedCell">15.41</td></tr><tr id="plyr167" class="pncPlayerRow playerTableBgRow1"><td class="playertableData">2</td><td class="playertablePlayerName" id="playername_167" style=""><a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="null" leagueId="0" playerId="167" teamId="-2147483648" cache="true">Joe Johnson</a>, Atl SG, SF<a href="" class="flexpop" content="tabs#ppc" instance="_ppc" fpopHeight="357px" fpopWidth="490px" tab="2" leagueId="0" playerId="167" teamId="-2147483648" cache="true"><img src="http://g.espncdn.com/s/fbalm/12/images/icons/sml/video_breaking.png" height="11" width="19" border="0" style="margin:0 6px 0 6px" title="Breaking Video" /></a></td><td class="sectionLeadingSpacer"></td><td class="playertableData">-0.62</td><td class="playertableData">1.70</td><td class="playertableData">3.41</td><td class="playertableData">0.41</td><td class="playertableData">1.48</td><td class="playertableData">0.79</td><td class="playertableData">0.04</td><td class="playertableData">2.27</td><td class="playerTableSpacerCell"></td><td class="playertableData sortedCell">9.47</td></tr><tr id="plyr265" class="pncPlayerRow playerTableBgRow0"><td
1,LAL SG0.632.411.441.292.821.840.184.8115.412,Atl SG,SF-0.621.703.410.411.480.790.042.279.47当移动到下一行时,您忘记重置tdCount
。每个玩家都获得了10次stst?
public static void main(String[] args) throws IOException, SQLException,
InterruptedException {
Document doc = Jsoup.connect(html).get();
String title = doc.title();
System.out.println(title);
int tdCount = 1;
String name = null;
Double stat1 = null;
Double stat2 = null;
Double stat3 = null;
Double stat4 = null;
Double stat5 = null;
Double stat6 = null;
Double stat7 = null;
Double stat8 = null;
Double stat9 = null;
Double stat10 = null;
Iterator<Element> trSIter = doc.select("table.playerTableTable")
.iterator();
while (trSIter.hasNext()) {
Element trEl = trSIter.next().child(0);
Elements tdEls = trEl.children();
Iterator<Element> tdIter = tdEls.select("tr").iterator();
boolean firstRow = true;
while (tdIter.hasNext()) {
Element tr = (Element) tdIter.next();
if (firstRow) {
firstRow = false;
continue;
}
while (tdIter.hasNext()) {
System.out.println("============================");
Element tdEl = tdIter.next();
name = tdEl.getElementsByClass("playertablePlayerName")
.text();
System.out.println("Name: " + name);
// System.out.println(tdEl);
Elements tdsEls = tdEl.select("td.playertableData");
Iterator<Element> columnIt = tdsEls.iterator();
boolean firstRow1 = true;
while (columnIt.hasNext()) {
Element td = (Element) columnIt.next();
if (firstRow1) {
firstRow1 = false;
continue;
}
while (columnIt.hasNext()) {
Element column = columnIt.next();
switch (tdCount++) {
case 1:
stat1 = Double.parseDouble(column.text());
break;
case 2:
stat2 = Double.parseDouble(column.text());
break;
case 3:
stat3 = Double.parseDouble(column.text());
break;
case 4:
stat4 = Double.parseDouble(column.text());
break;
case 5:
stat5 = Double.parseDouble(column.text());
break;
case 6:
stat6 = Double.parseDouble(column.text());
break;
case 7:
stat7 = Double.parseDouble(column.text());
break;
case 8:
stat8 = Double.parseDouble(column.text());
break;
case 9:
stat9 = Double.parseDouble(column.text());
break;
case 10:
stat10 = Double.parseDouble(column.text());
break;
}
// System.out.print(column.className()+":"+column.text()+",");
System.out.print("stat1: " + stat1 + " stat2: "
+ stat2 + " stat3: " + stat3 + " stat4: "
+ stat4 + " stat5: " + stat5 + " stat6: "
+ stat6 + " stat7: " + stat7 + " stat8: "
+ stat8 + " stat9: " + stat9 + " stat10: "
+ stat10);
}
}
System.out.println();
}
System.out.println();
}
}
}