Récupération de données dans un fichier HTML Acte III

Récupération de données dans un fichier HTML Acte III - Perl - Programmation

Marsh Posté le 26-08-2012 à 22:16:32    

Bonjour,
 
je reviens vers vous car j'ai un petit souci de récup de données. Je voudrais récupérer les données en gras dans le fichier HTML à la fin du message(qui provient de l'URL: http://www.betexplorer.com/soccer/ [...] /fixtures/ ) , mais j'aimerais que le résultat dans le fichier texte "cal_ligue1_2013_temp.txt" soit sous la forme:
 
3. Round
26.08.2012 21:00 Paris SG - Bordeaux
 
4. Round
01.09.2012 17:00 Lyon - Valenciennes
01.09.2012 20:00 Ajaccio - Evian TG
01.09.2012 20:00 Bastia - St Etienne
01.09.2012 20:00 Brest - Troyes
01.09.2012 20:00 Lorient - Nancy
01.09.2012 20:00 Sochaux - Montpellier
01.09.2012 20:00 Toulouse - Reims
02.09.2012 14:00 Bordeaux - Nice
02.09.2012 17:00 Marseille - Rennes
02.09.2012 21:00 Lille - Paris SG
 
5. Round
15.09.2012 19:00 Evian TG - Bastia
15.09.2012 19:00 Lyon - Ajaccio
15.09.2012 19:00 Nancy - Marseille
15.09.2012 19:00 Nice - Brest
15.09.2012 19:00 Paris SG - Toulouse
15.09.2012 19:00 Reims - Montpellier
15.09.2012 19:00 Rennes - Lorient
15.09.2012 19:00 St Etienne - Sochaux
15.09.2012 19:00 Troyes - Lille
15.09.2012 19:00 Valenciennes - Bordeaux
 
6. Round
......
 
 
or pour l'instant j'arrive à récupérer cela:
 
3. Round
 
26.08.2012 21:00 Paris SG - Bordeaux
4. Round
 
01.09.2012 17:00 Lyon - Valenciennes
01.09.2012 20:00 Ajaccio - Evian TG
† Bastia - St Etienne
† Brest - Troyes
† Lorient - Nancy
† Sochaux - Montpellier
† Toulouse - Reims
02.09.2012 14:00 Bordeaux - Nice
02.09.2012 17:00 Marseille - Rennes
02.09.2012 21:00 Lille - Paris SG
5. Round
 
15.09.2012 19:00 Evian TG - Bastia
† Lyon - Ajaccio
† Nancy - Marseille
† Nice - Brest
† Paris SG - Toulouse
† Reims - Montpellier
† Rennes - Lorient
† St Etienne - Sochaux
† Troyes - Lille
† Valenciennes - Bordeaux
6. Round
....
 
 
Le problème est que le fichier HTML n'est pas symétrique et je ne peux pas récupérer les dates correspondantes aux matchs qui se jouent le même jour et à a même heure(à part le premier match) car elles ne figurent pas dans la balise <td class="first-cell date tl">, il y a un &nbsp; . J'essaie depuis un petit moment mais je ne sais pas ce qui est le mieux, faut-il modifier mon script calfrance_2013.pl ou alors retravailler le fichier obtenu avec les espèces de petites croix ? Là je suis complètement perdu, j'ai essayer une sorte de boucle sur le fichier obtenu avec une regex pour essayer de remplacer les &nbsp; par la date qui est sur la ligne précédente mais sans succès !! D'ailleurs je sais pas si c'est possible de récupérer une variable sur une ligne précédente avec les regex et une boucle .... enfin avec PERL ça doit être possible :).
Merci à vous pour un petit coup de main.
 
Voici mon fichier calfrance_2013.pl:

Code :
  1. #!C:/Perl/bin/perl.exe -w
  2. use strict; use warnings;
  3. use HTML::TreeBuilder;
  4. use LWP::Simple;
  5. ######################################
  6. #                  #
  7. #  Récupération du calendrier des 3 championnats Français      #
  8. #    Ligue1 - Ligue2 - National         #
  9. #  dans les fichiers  cal_ligue1_2013.txt ;                  #
  10. #  cal_ligue2_2013.txt et cal_national_2013.txt               #
  11. #                               #
  12. #######################################              
  13. open(A,">cal_ligue1_2013_temp.txt" );
  14. my $url1 = 'http://www.betexplorer.com/soccer/france/ligue-1/fixtures/';
  15. my $tree = HTML::TreeBuilder->new_from_content(get($url1));
  16. my ($td, $th, $a, $att, @infos, @content);  #les variables utiles
  17. my @tr = $tree->find('tr');
  18. foreach (@tr) {
  19.   @infos = ();
  20.   @content = ();
  21.   my $att = $_->attr("class" );
  22.   if ($att and $att =~ /rtitle/) { #si tr avec attribut class avec rtitle, on y cherche un th
  23.     $th = $_->look_down("_tag", "th", "class", "left first-cell nobr" );
  24.     next unless ($th);
  25.     @content = $th->content_list();
  26.     print A $content[0], "\n";
  27.   }
  28.   else {  #sinon on est dans le cas <td> sous <tr>
  29.     $td = $_->look_down("_tag", "td", "class", "first-cell date tl" );
  30.     next unless ($td);
  31.     @content = $td->content_list();
  32.     push @infos, $content[0];
  33.     $td = $td->right;
  34.     $a = $td->find('a');
  35.     next unless ($a);
  36.     @content = $a->content_list();
  37.     push @infos, $content[0];
  38.     }
  39.     print A "@infos\n";
  40.   }
  41. close A;


 
 
Fichier HTML:

Spoiler :


<tr class="rtitle first-row">
   <th class="left first-cell nobr" colspan="2">3. Round</th>
   <th class="tv">&nbsp;</th>
   <th class="bs">B's</th>
   <th>1</th>
   <th>X</th>
   <th class="last-cell nobr">2</th>
</tr>
<tr class="match-line first-row">
   <td class="first-cell date tl">26.08.2012 21:00</td>
   <td class="tl nobr"><a href="../nextmatch.php?matchid=1335840">Paris SG - Bordeaux</a></th>
   <td class="tv"><img src="/res/img/icon-tv.gif" onmouseover="showStreams(1335840);" onmouseout="hideStreams(1335840);"/><div class="streams" id="streams1335840" onmouseover="showStreams(1335840);" onmouseout="hideStreams(1335840);"><div class="head">Live streams</div><div class="body"><a href="/bookmaker/11/http://www.bet365.com?affiliate=365_021894" target="_blank">bet365</a><br /></div></div></td>
   <td class="bs">44</td>
   <td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335840&amp;outcomeid=46281338&amp;otheroutcomes=46281337,46281339" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.60</a></span></td>
   <td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335840&amp;outcomeid=46281337&amp;otheroutcomes=46281338,46281339" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.60</a></span></td>
   <td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335840&amp;outcomeid=46281339&amp;otheroutcomes=46281338,46281337" title="Add to My Selections" target="mySelections" class="mySelectionsTip">6.10</a></span></td>
</tr>
<tr class="rtitle">
   <th class="left first-cell nobr" colspan="2">4. Round</th>
   <th class="tv">&nbsp;</th>
   <th class="bs">B's</th>
   <th>1</th>
   <th>X</th>
   <th class="last-cell nobr">2</th>
</tr>
<tr class="match-line first-row">
   <td class="first-cell date tl">01.09.2012 17:00</td>
   <td class="tl nobr"><a href="../nextmatch.php?matchid=1335849">Lyon - Valenciennes</a></th>
   <td class="tv">&nbsp;</td>
   <td class="bs">3</td>
   <td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335849&amp;outcomeid=48941506&amp;otheroutcomes=48941505,48941507" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.44</a></span></td>
   <td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335849&amp;outcomeid=48941505&amp;otheroutcomes=48941506,48941507" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.80</a></span></td>
   <td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335849&amp;outcomeid=48941507&amp;otheroutcomes=48941506,48941505" title="Add to My Selections" target="mySelections" class="mySelectionsTip">8.08</a></span></td>
</tr>
<tr class="match-line strong">
   <td class="first-cell date tl">01.09.2012 20:00</td>
   <td class="tl nobr"><a href="../nextmatch.php?matchid=1335844">Ajaccio - Evian TG</a></th>
   <td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335844&amp;outcomeid=48941517&amp;otheroutcomes=48941516,48941518" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.42</a></span></td>
   <td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335844&amp;outcomeid=48941516&amp;otheroutcomes=48941517,48941518" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.07</a></span></td>
   <td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335844&amp;outcomeid=48941518&amp;otheroutcomes=48941517,48941516" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.95</a></span></td>
</tr>
<tr class="match-line">
   <td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335850">Bastia - St Etienne</a></th><td class="tv">&nbsp;</td>
   <td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335850&amp;outcomeid=48941501&amp;otheroutcomes=48941498,48941502" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.42</a></span></td>
   <td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335850&amp;outcomeid=48941498&amp;otheroutcomes=48941501,48941502" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.07</a></span></td>
   <td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335850&amp;outcomeid=48941502&amp;otheroutcomes=48941501,48941498" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.95</a></span></td>
</tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335851">Brest - Troyes</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335851&amp;outcomeid=48941528&amp;otheroutcomes=48941527,48941529" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.95</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335851&amp;outcomeid=48941527&amp;otheroutcomes=48941528,48941529" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.13</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335851&amp;outcomeid=48941529&amp;otheroutcomes=48941528,48941527" title="Add to My Selections" target="mySelections" class="mySelectionsTip">4.02</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335845">Lorient - Nancy</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335845&amp;outcomeid=48941533&amp;otheroutcomes=48941532,48941534" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.08</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335845&amp;outcomeid=48941532&amp;otheroutcomes=48941533,48941534" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.03</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335845&amp;outcomeid=48941534&amp;otheroutcomes=48941533,48941532" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.67</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335846">Sochaux - Montpellier</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335846&amp;outcomeid=48941538&amp;otheroutcomes=48941537,48941539" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.07</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335846&amp;outcomeid=48941537&amp;otheroutcomes=48941538,48941539" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.03</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335846&amp;outcomeid=48941539&amp;otheroutcomes=48941538,48941537" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.35</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335852">Toulouse - Reims</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335852&amp;outcomeid=48941543&amp;otheroutcomes=48941542,48941544" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.71</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335852&amp;outcomeid=48941542&amp;otheroutcomes=48941543,48941544" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.33</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335852&amp;outcomeid=48941544&amp;otheroutcomes=48941543,48941542" title="Add to My Selections" target="mySelections" class="mySelectionsTip">5.10</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">02.09.2012 14:00</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335847">Bordeaux - Nice</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335847&amp;outcomeid=48941548&amp;otheroutcomes=48941547,48941550" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.73</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335847&amp;outcomeid=48941547&amp;otheroutcomes=48941548,48941550" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.32</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335847&amp;outcomeid=48941550&amp;otheroutcomes=48941548,48941547" title="Add to My Selections" target="mySelections" class="mySelectionsTip">5.00</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">02.09.2012 17:00</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335848">Marseille - Rennes</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335848&amp;outcomeid=48941556&amp;otheroutcomes=48941555,48941557" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.07</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335848&amp;outcomeid=48941555&amp;otheroutcomes=48941556,48941557" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.10</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335848&amp;outcomeid=48941557&amp;otheroutcomes=48941556,48941555" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.62</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">02.09.2012 21:00</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335853">Lille - Paris SG</a></th><td class="tv">&nbsp;</td><td class="bs">3</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335853&amp;outcomeid=48941591&amp;otheroutcomes=48941590,48941592" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.58</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335853&amp;outcomeid=48941590&amp;otheroutcomes=48941591,48941592" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.07</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335853&amp;outcomeid=48941592&amp;otheroutcomes=48941591,48941590" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.74</a></span></td></tr>
<tr class="rtitle"><th class="left first-cell nobr" colspan="2">5. Round</th><th class="tv">&nbsp;</th><th class="bs">B's</th><th>1</th><th>X</th><th class="last-cell nobr">2</th></tr>
<tr class="match-line first-row"><td class="first-cell date tl">15.09.2012 19:00</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335857">Evian TG - Bastia</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335857&amp;outcomeid=48941599&amp;otheroutcomes=48941598,48941600" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.00</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335857&amp;outcomeid=48941598&amp;otheroutcomes=48941599,48941600" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.20</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335857&amp;outcomeid=48941600&amp;otheroutcomes=48941599,48941598" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.90</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335859">Lyon - Ajaccio</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335859&amp;outcomeid=48941604&amp;otheroutcomes=48941603,48941606" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.35</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335859&amp;outcomeid=48941603&amp;otheroutcomes=48941604,48941606" title="Add to My Selections" target="mySelections" class="mySelectionsTip">4.25</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335859&amp;outcomeid=48941606&amp;otheroutcomes=48941604,48941603" title="Add to My Selections" target="mySelections" class="mySelectionsTip">10.50</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335854">Nancy - Marseille</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335854&amp;outcomeid=48941615&amp;otheroutcomes=48941614,48941616" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.90</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335854&amp;outcomeid=48941614&amp;otheroutcomes=48941615,48941616" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.15</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335854&amp;outcomeid=48941616&amp;otheroutcomes=48941615,48941614" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.45</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335858">Nice - Brest</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335858&amp;outcomeid=48941623&amp;otheroutcomes=48941622,48941624" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.15</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335858&amp;outcomeid=48941622&amp;otheroutcomes=48941623,48941624" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.10</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335858&amp;outcomeid=48941624&amp;otheroutcomes=48941623,48941622" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.55</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335860">Paris SG - Toulouse</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335860&amp;outcomeid=48941633&amp;otheroutcomes=48941630,48941635" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.40</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335860&amp;outcomeid=48941630&amp;otheroutcomes=48941633,48941635" title="Add to My Selections" target="mySelections" class="mySelectionsTip">4.00</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335860&amp;outcomeid=48941635&amp;otheroutcomes=48941633,48941630" title="Add to My Selections" target="mySelections" class="mySelectionsTip">9.50</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335861">Reims - Montpellier</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335861&amp;outcomeid=48941642&amp;otheroutcomes=48941641,48941643" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.15</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335861&amp;outcomeid=48941641&amp;otheroutcomes=48941642,48941643" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.10</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335861&amp;outcomeid=48941643&amp;otheroutcomes=48941642,48941641" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.30</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335862">Rennes - Lorient</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335862&amp;outcomeid=48941650&amp;otheroutcomes=48941649,48941651" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.85</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335862&amp;outcomeid=48941649&amp;otheroutcomes=48941650,48941651" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.40</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335862&amp;outcomeid=48941651&amp;otheroutcomes=48941650,48941649" title="Add to My Selections" target="mySelections" class="mySelectionsTip">4.25</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335855">St Etienne - Sochaux</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335855&amp;outcomeid=48941655&amp;otheroutcomes=48941654,48941656" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.80</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335855&amp;outcomeid=48941654&amp;otheroutcomes=48941655,48941656" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.45</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335855&amp;outcomeid=48941656&amp;otheroutcomes=48941655,48941654" title="Add to My Selections" target="mySelections" class="mySelectionsTip">4.40</a></span></td></tr>
<tr class="match-line"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335856">Troyes - Lille</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335856&amp;outcomeid=48941660&amp;otheroutcomes=48941659,48941661" title="Add to My Selections" target="mySelections" class="mySelectionsTip">4.10</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335856&amp;outcomeid=48941659&amp;otheroutcomes=48941660,48941661" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.30</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335856&amp;outcomeid=48941661&amp;otheroutcomes=48941660,48941659" title="Add to My Selections" target="mySelections" class="mySelectionsTip">1.90</a></span></td></tr>
<tr class="match-line strong"><td class="first-cell date tl">&nbsp;</td><td class="tl nobr"><a href="../nextmatch.php?matchid=1335863">Valenciennes - Bordeaux</a></th><td class="tv">&nbsp;</td><td class="bs">1</td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335863&amp;outcomeid=48941665&amp;otheroutcomes=48941664,48941666" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.70</a></span></td><td class="odds"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335863&amp;outcomeid=48941664&amp;otheroutcomes=48941665,48941666" title="Add to My Selections" target="mySelections" class="mySelectionsTip">3.15</a></span></td><td class="odds nobr last-cell"><span><a href="/my_selections.php?sportid=1&action=3&amp;matchid=1335863&amp;outcomeid=48941666&amp;otheroutcomes=48941665,48941664" title="Add to My Selections" target="mySelections" class="mySelectionsTip">2.60</a></span></td></tr>
<tr class="rtitle"><th class="left first-cell nobr" colspan="2">6. Round</th><th class="tv">&nbsp;</th><th class="bs">B's</th><th>1</th><th>X</th><th class="last-cell nobr">2</th></tr>


Message édité par thales69 le 26-08-2012 à 22:46:26
Reply

Marsh Posté le 26-08-2012 à 22:16:32   

Reply

Marsh Posté le 31-08-2012 à 14:14:58    

:hello:  
J'étais pris cette semaine, je viens d'y jeter un oeil.
Ceci devrait faire l'affaire:
 

Code :
  1. #!C:/Perl/bin/perl.exe
  2. use strict;
  3. use warnings;
  4. use HTML::TreeBuilder;
  5. ################################################################
  6. #                                                             #
  7. #  Récupération du calendrier des 3 championnats Français      #
  8. #    Ligue1 - Ligue2 - National                             #
  9. #  dans les fichiers  cal_ligue1_2013.txt ;                    #
  10. #  cal_ligue2_2013.txt et cal_national_2013.txt                   #
  11. #                                                           #
  12. ################################################################
  13. open(A,">cal_ligue1_2013_temp.txt" );
  14.  
  15. my $url1 = 'http://www.betexplorer.com/soccer/france/ligue-1/fixtures/';
  16. my $tree = HTML::TreeBuilder->new_from_url($url1);
  17. my ($td, $th, $a, $att, @infos, @content, $schedule);  #les variables utiles
  18. my @tr = $tree->find('tr');
  19. foreach (@tr) {
  20.  @infos = ();
  21.  @content = ();
  22.  my $att = $_->attr("class" );
  23.  if ($att and $att =~ /rtitle/) { #si tr avec attribut class avec rtitle, on y cherche un th
  24.    $th = $_->look_down("_tag", "th", "class", "left first-cell nobr" );
  25.    next unless ($th);
  26.    @content = $th->content_list();
  27.    print A "\n$content[0]";
  28.  }
  29.  else {  #sinon on est dans le cas <td> sous <tr>
  30.    $td = $_->look_down("_tag", "td", "class", "first-cell date tl" );
  31.    next unless ($td);
  32.    @content = $td->content_list();
  33.    if ($content[0] =~ /\d/) {
  34.      $schedule = $content[0];
  35.    }
  36.    push @infos, $schedule;
  37.    $td = $td->right;
  38.    $a = $td->find('a');
  39.    next unless ($a);
  40.    @content = $a->content_list();
  41.    push @infos, $content[0];
  42.    }
  43.    print A "@infos\n";
  44.  }
  45.  


my $tree = HTML::TreeBuilder->new_from_url($url1);
c'est plus simple et ça évite de faire un appel explicite à LWP::Simple
my ($td, $th, $a, $att, @infos, @content, $schedule);  #les variables utiles
Je rajoute $schedule pour y placer la dernière date valide trouvée
print A "\n$content[0]";
ça va éviter de séparer la ligne Round de la ligne qui suit par une ligne vide et ça mettra une ligne vide avant chaque nouveau Round
    if ($content[0] =~ /\d/) {
      $schedule = $content[0];
    }
Si on trouve une nouvelle date valide (On teste juste si le champ contient un chiffre) on la met dans $schedule (sinon, on garde la dernière date valide trouvée)
push @infos, $schedule;
Et c'est cette date valide courante qu'on stocke.
C'est tout.
 
En sortie j'ai:

4. Round
01.09.2012 17:00 Lyon - Valenciennes
01.09.2012 20:00 Ajaccio - Evian TG
01.09.2012 20:00 Bastia - St Etienne
01.09.2012 20:00 Brest - Troyes
01.09.2012 20:00 Lorient - Nancy
01.09.2012 20:00 Sochaux - Montpellier
01.09.2012 20:00 Toulouse - Reims
02.09.2012 14:00 Bordeaux - Nice
02.09.2012 17:00 Marseille - Rennes
02.09.2012 21:00 Lille - Paris SG
 
5. Round
15.09.2012 19:00 Evian TG - Bastia
15.09.2012 19:00 Lyon - Ajaccio
15.09.2012 19:00 Nancy - Marseille
15.09.2012 19:00 Nice - Brest
15.09.2012 19:00 Paris SG - Toulouse
15.09.2012 19:00 Reims - Montpellier
15.09.2012 19:00 Rennes - Lorient
15.09.2012 19:00 St Etienne - Sochaux
15.09.2012 19:00 Troyes - Lille
15.09.2012 19:00 Valenciennes - Bordeaux
.....................


A+,


Message édité par gilou le 31-08-2012 à 14:17:32

---------------
There's more than what can be linked! --    Iyashikei Anime Forever!    --  AngularJS c'est un framework d'engulé!  --
Reply

Marsh Posté le 31-08-2012 à 15:10:42    

Juste trop fort Gilou !!! ça marche impec.
 
Merci beaucoup à toi ... pour la leçon, j'en apprends des tonnes chaque fois que tu postes :)
 
A+


Message édité par thales69 le 31-08-2012 à 15:12:42
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed