CODE:
@Override
protected String doInBackground(String... params) {
try {
Document doc = Jsoup.connect("http://www.diretta.it/").get();
Elements partite = doc.select("div.table-main > table.soccer");
for(Element partita : partite)//per ogni sezione tra gli elementi ricavati prima
{
//ricavo ogni riga nella sezione
Elements righe = partita.select("tbody > tr");
for(Element riga : righe){
//prenso il tempo di inizi
String Time = riga.select("td.cell_ad.time").text();
//prendo il tempo trascorso
String Timer = riga.select("td.cell_aa.timer > span").text();
//prendo lo score
String Score = riga.select("td.cell_sa.score").text();
//prendo il nome del team1
String Team1 = riga.select("td.cell_ab.team-home > span").text();
//prendo il nome del team2
String Team2 = riga.select("td.cell_ac.team-away > span").text();
//aggiungo alle liste
Times.add(Time);
Timers.add(Timer);
Scores.add(Score);
Teams1.add(Team1);
Teams2.add(Team2);
}
}
} catch (Exception e) {
// gestione dell'eccezione
Log.e("PROBLEMA", "ERRORE NEL PARSING");
}
return null;
}
private List createList(int size) {
List result = new ArrayList();
for (int i=0; i <= size; i++) {
CardInfo card = new CardInfo();
card.team1 = CardInfo.TEAM1_PREFIX + Teams1.get(i);
card.team2 = CardInfo.TEAM2_PREFIX + Teams2.get(i);
card.score = CardInfo.SCORE_PREFIX + Scores.get(i);
card.timer = CardInfo.TIMER_PREFIX + Timers.get(i);
result.add(card);
}
return result;
}
@Override
protected void onPostExecute(String result)
{
// dopo che ho eseguito il parsing mostro i dati nella listview
if(Times.size()==0){
Log.e("TIMES", "ERRORE NEL PARSING");
}
if(Teams1.size()==0){
Log.e("TEAMS1", "ERRORE NEL PARSING");
}
if(Teams2.size()==0){
Log.e("TEAMS2", "ERRORE NEL PARSING");
}
if(Scores.size()==0){
Log.e("SCORES", "ERRORE NEL PARSING");
}
if(Timers.size()==0){
Log.e("TIMERS", "ERRORE NEL PARSING");
}
CardAdapter cardadapt = new CardAdapter(createList(Teams1.size()));
recyclerList.setAdapter(cardadapt);
}
}
LogCat
-24 16:19:58.339 27554-27575/com.gheoo.direttagol I/OpenGLRenderer﹕ Initialized EGL, version 1.4
04-24 16:19:58.354 27554-27575/com.gheoo.direttagol D/OpenGLRenderer﹕ Enabling debug mode 0
04-24 16:19:58.376 27554-27554/com.gheoo.direttagol E/RecyclerView﹕ No adapter attached; skipping layout
04-24 16:19:58.388 27554-27554/com.gheoo.direttagol E/RecyclerView﹕ No adapter attached; skipping layout
04-24 16:19:59.028 27554-27554/com.gheoo.direttagol E/TIMES﹕ ERRORE NEL PARSING
04-24 16:19:59.028 27554-27554/com.gheoo.direttagol E/TEAMS1﹕ ERRORE NEL PARSING
04-24 16:19:59.028 27554-27554/com.gheoo.direttagol E/TEAMS2﹕ ERRORE NEL PARSING
04-24 16:19:59.028 27554-27554/com.gheoo.direttagol E/SCORES﹕ ERRORE NEL PARSING
04-24 16:19:59.028 27554-27554/com.gheoo.direttagol E/TIMERS﹕ ERRORE NEL PARSING
04-24 16:19:59.028 27554-27554/com.gheoo.direttagol D/AndroidRuntime﹕ Shutting down VM
04-24 16:19:59.030 27554-27554/com.gheoo.direttagol E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.gheoo.direttagol, PID: 27554
java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at com.gheoo.direttagol.Tab1$ParsingHome.createList(Tab1.java:101)
at com.gheoo.direttagol.Tab1$ParsingHome.onPostExecute(Tab1.java:140)
at com.gheoo.direttagol.Tab1$ParsingHome.onPostExecute(Tab1.java:40)
at android.os.AsyncTask.finish(AsyncTask.java:636)
at android.os.AsyncTask.access$500(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:653)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
line 40 ----> private class ParsingHome extends AsyncTask { line 101-----> card.team1 = CardInfo.TEAM1_PREFIX + Teams1.get(i); line 140----> CardAdapter cardadapt = new CardAdapter(createList(Teams1.size()));
Where is the problem ? i don't know.... the page is www.diretta.it
HTML
<div id="fs" class="fs-table" style="opacity: 1;"><div class="table-main"><table class="soccer"><colgroup><col width="55"><col width="80"><col width="191"><col width="57"><col width="191"><col width="51"><col width="68"><col width="23"></colgroup><thead><tr class="league l_1_EDRix5yC primary-top"><td colspan="7" class="head_ab "> <span class="stats-link link-tables fsh"><span class="stats" title="Classifiche">Classifiche</span></span><span class="country right"><span class="flag fl_77 right"></span><span class="name"><span class="country_part">FRANCIA: </span><span class="tournament_part">Ligue 1</span></span></span><span class="toggleMyLeague active 1_77_KIShoMk3" title="Rimuovi questo campionato da Miei Campionati!" onclick="cjs.myLeagues.toggleTop('1_77_KIShoMk3'); return false;"></span></td><td colspan="1" class="head_aa "><div class="dicons"><span class="icons right"><span id="latomyg_1_EDRix5yC" class="tomyg"></span></span></div></td></tr></thead><tbody><tr id="g_1_Um035rWn" class="tr-first stage-scheduled"><td class="cell_ad time ">17:00</td><td class="cell_aa timer "><span> </span></td><td class="cell_ab team-home "><span class="padr">Paris SG</span></td><td class="cell_sa score ">-</td><td class="cell_ac team-away "><span class="padl">Lilla</span></td><td class="cell_sb part-top "><span class="icons"><span class="live-centre"></span></span></td><td class="cell_ia icons "><span class="icons"><span class="tv icon1"></span><span class="slive icon2"></span></span></td><td class="cell_ib icons "><span class="icons right"><span class="tomyg icon0"></span></span></td></tr><tr id="g_1_0Yytls1C" class="even stage-scheduled"><td class="cell_ad time ">20:00</td><td class="cell_aa timer "><span> </span></td><td class="cell_ab team-home "><span class="padr">Bordeaux</span></td><td class="cell_sa score ">-</td><td class="cell_ac team-away "><span class="padl">Metz</span></td><td class="cell_sb part-top "><span class="icons"><span class="live-centre"></span></span></td><td class="cell_ia icons "><span class="icons"><span class="tv icon1"></span><span class="slive icon2"></span></span></td><td class="cell_ib icons "><span class="icons right"><span class="tomyg icon0"></span></span></td></tr><tr id="g_1_I9Wpm1GI" class=" stage-scheduled" style="cursor: pointer;"><td class="cell_ad time">20:00</td><td class="cell_aa timer"><span> </span></td><td class="cell_ab team-home" title="Clicca per i dettagli dell'incontro!"><span class="padr">Caen</span></td><td class="cell_sa score">-</td><td class="cell_ac team-away"><span class="padl">Guingamp</span></td><td class="cell_sb part-top"><span class="icons"><span class="live-centre"></span></span></td><td class="cell_ia icons"><span class="icons"><span class="tv icon1"></span><span class="slive icon2"></span></span></td><td class="cell_ib icons"><span class="icons right"><span class="tomyg icon0"></span></span></td></tr><tr id="g_1_d0VlnLVO" class="even stage-scheduled"><td class="cell_ad time ">20:00</td><td class="cell_aa timer "><span> </span></td><td class="cell_ab team-home "><span class="padr">Evian TG</span></td><td class="cell_sa score ">-</td><td class="cell_ac team-away "><span class="padl">Bastia</span></td><td class="cell_sb part-top "><span class="icons"><span class="live-centre"></span></span></td><td class="cell_ia icons "><span class="icons"><span class="tv icon1"></span><span class="slive icon2"></span></span></td><td class="cell_ib icons "><span class="icons right"><span class="tomyg icon0"></span></span></td></tr><tr id="g_1_G4bB3M0a" class=" stage-scheduled"><td class="cell_ad time ">20:00</td><td class="cell_aa timer "><span> </span></td><td class="cell_ab team-home "><span class="padr">Rennes</span></td><td class="cell_sa score ">-</td><td class="cell_ac team-away "><span class="padl">Nizza</span></td><td class="cell_sb part-top "><span class="icons"><span class="live-centre"></span></span></td><td class="cell_ia icons "><span class="icons"><span class="tv icon1"></span><span class="slive icon2"></span></span></td><td class="cell_ib icons "><span class="icons right"><span class="tomyg icon0"></span></span></td></tr><tr id="g_1_xKnK10VB" class="even stage-scheduled"><td class="cell_ad time ">20:00</td><td class="cell_aa timer "><span> </span></td><td class="cell_ab team-home "><span class="padr">Tolosa</span></td><td class="cell_sa score ">-</td><td class="cell_ac team-away "><span class="padl">Nantes</span></td><td class="cell_sb part-top "><span class="icons"><span class="live-centre"></span></span></td><td class="cell_ia icons "><span class="icons"><span class="tv icon1"></span><span class="slive icon2"></span></span></td><td class="cell_ib icons "><span class="icons right"><span class="tomyg icon0"></span></span></td></tr></tbody></table></div></div>