thales69 | Bonjour,
me revoilà avec un problème que je n'arrive pas résoudre. J'essaie dans le fichier HTML ci-dessous de récupérer les données en gras.
En fait j'aimerais avoir un fichier texte (resfrance1.txt) qui me donnerait le résultat suivant, la journée de championnat, les deux équipes qui se rencontrent, le score et la date.
36. Round
Rennes - Montpellier 0:2 07.05.2012
Auxerre - Bordeaux 2:4 07.05.2012
Lille - Caen 3:0 07.05.2012
Lorient - Dijon 0:0 07.05.2012
St Etienne - Marseille 0:0 07.05.2012
Sochaux - Nancy 1:0 07.05.2012
Toulouse- Nice 0:0 07.05.2012
Valenciennes - Paris SG 3:4 06.05.2012
Evian TG - Ajaccio 2:1 06.05.2012
Lyon - Brest 1:1 06.05.2012
35. Round
Dijon - Auxerre 0:2 03.05.2012
Paris SG - St Etienne 2:0 02.05.2012
......
jusqu'à la 1ère journée(1. Round)
Fichier HTML
Code :
- <table class="result-table league-results" cellspacing="0" id="resultstable"><tr class="rtitle first-row"><th class="left first-cell">36. Round</th><th> </th><th>1</th><th>X</th><th>2</th><th class="nobr last-cell"> </th></tr>
- <tr class="first-row"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797630" onclick="win(this.href, 500, 500, 0, 1); return false;">Rennes - Montpellier</a></td><td>0:2 (0:1, 0:1)</td><td class="odds">2.39</td><td class="odds">3.13</td><td class="odds best-betrate">2.97</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797625" onclick="win(this.href, 500, 500, 0, 1); return false;">Auxerre - Bordeaux</a></td><td>2:4 (0:3, 2:1)</td><td class="odds">2.26</td><td class="odds">3.18</td><td class="odds best-betrate">3.13</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797627" onclick="win(this.href, 500, 500, 0, 1); return false;">Lille - Caen</a></td><td>3:0 (2:0, 1:0)</td><td class="odds best-betrate">1.26</td><td class="odds">5.36</td><td class="odds">10.85</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797628" onclick="win(this.href, 500, 500, 0, 1); return false;">Lorient - Dijon</a></td><td>0:0 (0:0, 0:0)</td><td class="odds">1.77</td><td class="odds best-betrate">3.36</td><td class="odds">4.72</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797631" onclick="win(this.href, 500, 500, 0, 1); return false;">St Etienne - Marseille</a></td><td>0:0 (0:0, 0:0)</td><td class="odds">2.22</td><td class="odds best-betrate">3.19</td><td class="odds">3.20</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797632" onclick="win(this.href, 500, 500, 0, 1); return false;">Sochaux - Nancy</a></td><td>1:0 (0:0, 1:0)</td><td class="odds best-betrate">2.31</td><td class="odds">3.13</td><td class="odds">3.09</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797633" onclick="win(this.href, 500, 500, 0, 1); return false;">Toulouse - Nice</a></td><td>0:0 (0:0, 0:0)</td><td class="odds">1.71</td><td class="odds best-betrate">3.37</td><td class="odds">5.16</td><td class="last-cell nobr date">07.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797634" onclick="win(this.href, 500, 500, 0, 1); return false;">Valenciennes - Paris SG</a></td><td>3:4 (2:3, 1:1)</td><td class="odds">4.30</td><td class="odds">3.34</td><td class="odds best-betrate">1.83</td><td class="last-cell nobr date">06.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797626" onclick="win(this.href, 500, 500, 0, 1); return false;">Evian TG - Ajaccio</a></td><td>2:1 (1:1, 1:0)</td><td class="odds best-betrate">1.98</td><td class="odds">3.29</td><td class="odds">3.71</td><td class="last-cell nobr date">06.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797629" onclick="win(this.href, 500, 500, 0, 1); return false;">Lyon - Brest</a></td><td>1:1 (1:0, 0:1)</td><td class="odds">1.38</td><td class="odds best-betrate">4.37</td><td class="odds">7.99</td><td class="last-cell nobr date">06.05.2012</td></tr>
- <tr class="rtitle"><th class="left first-cell">35. Round</th><th> </th><th>1</th><th>X</th><th>2</th><th class="nobr last-cell"> </th></tr>
- <tr class="first-row"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797619" onclick="win(this.href, 500, 500, 0, 1); return false;">Dijon - Auxerre</a></td><td>0:2 (0:1, 0:1)</td><td class="odds">2.55</td><td class="odds">3.12</td><td class="odds best-betrate">2.76</td><td class="last-cell nobr date">03.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797624" onclick="win(this.href, 500, 500, 0, 1); return false;">Paris SG - St Etienne</a></td><td>2:0 (1:0, 1:0)</td><td class="odds best-betrate">1.50</td><td class="odds">4.01</td><td class="odds">6.26</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797615" onclick="win(this.href, 500, 500, 0, 1); return false;">Ajaccio - Sochaux</a></td><td>2:1 (0:0, 2:1)</td><td class="odds best-betrate">2.17</td><td class="odds">3.13</td><td class="odds">3.40</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797616" onclick="win(this.href, 500, 500, 0, 1); return false;">Bordeaux - Rennes</a></td><td>2:0 (0:0, 2:0)</td><td class="odds best-betrate">2.36</td><td class="odds">3.10</td><td class="odds">3.03</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797617" onclick="win(this.href, 500, 500, 0, 1); return false;">Brest - Toulouse</a></td><td>0:0 (0:0, 0:0)</td><td class="odds">2.89</td><td class="odds best-betrate">3.00</td><td class="odds">2.54</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797618" onclick="win(this.href, 500, 500, 0, 1); return false;">Caen - Lorient</a></td><td>1:0 (0:0, 1:0)</td><td class="odds best-betrate">2.37</td><td class="odds">3.08</td><td class="odds">3.03</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797620" onclick="win(this.href, 500, 500, 0, 1); return false;">Lyon - Valenciennes</a></td><td>4:1 (1:1, 3:0)</td><td class="odds best-betrate">1.63</td><td class="odds">3.63</td><td class="odds">5.40</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797621" onclick="win(this.href, 500, 500, 0, 1); return false;">Marseille - Nancy</a></td><td>1:0 (1:0, 0:0)</td><td class="odds best-betrate">1.59</td><td class="odds">3.74</td><td class="odds">5.58</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797623" onclick="win(this.href, 500, 500, 0, 1); return false;">Nice - Lille</a></td><td>0:1 (0:1, 0:0)</td><td class="odds">4.35</td><td class="odds">3.38</td><td class="odds best-betrate">1.82</td><td class="last-cell nobr date">02.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797622" onclick="win(this.href, 500, 500, 0, 1); return false;">Montpellier - Evian TG</a></td><td>2:2 (1:1, 1:1)</td><td class="odds">1.38</td><td class="odds best-betrate">4.29</td><td class="odds">8.62</td><td class="last-cell nobr date">01.05.2012</td></tr>
- <tr class="rtitle"><th class="left first-cell">34. Round</th><th> </th><th>1</th><th>X</th><th>2</th><th class="nobr last-cell"> </th></tr>
- <tr class="first-row"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797606" onclick="win(this.href, 500, 500, 0, 1); return false;">Evian TG - Lyon</a></td><td>1:3 (1:1, 0:2)</td><td class="odds">3.04</td><td class="odds">3.29</td><td class="odds best-betrate">2.25</td><td class="last-cell nobr date">10.05.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797607" onclick="win(this.href, 500, 500, 0, 1); return false;">Lille - Paris SG</a></td><td>2:1 (0:0, 2:1)</td><td class="odds best-betrate">2.11</td><td class="odds">3.38</td><td class="odds">3.25</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797605" onclick="win(this.href, 500, 500, 0, 1); return false;">Auxerre - Brest</a></td><td>4:0 (4:0, 0:0)</td><td class="odds best-betrate">2.04</td><td class="odds">3.11</td><td class="odds">3.76</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797609" onclick="win(this.href, 500, 500, 0, 1); return false;">Nancy - Caen</a></td><td>1:1 (0:0, 1:1)</td><td class="odds">1.99</td><td class="odds best-betrate">3.18</td><td class="odds">3.82</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797610" onclick="win(this.href, 500, 500, 0, 1); return false;">Rennes - Ajaccio</a></td><td>3:1 (1:0, 2:1)</td><td class="odds best-betrate">1.42</td><td class="odds">4.16</td><td class="odds">7.69</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797611" onclick="win(this.href, 500, 500, 0, 1); return false;">St Etienne - Dijon</a></td><td>1:0 (1:0, 0:0)</td><td class="odds best-betrate">1.67</td><td class="odds">3.53</td><td class="odds">5.17</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797612" onclick="win(this.href, 500, 500, 0, 1); return false;">Sochaux - Bordeaux</a></td><td>0:3 (0:1, 0:2)</td><td class="odds">2.42</td><td class="odds">3.11</td><td class="odds best-betrate">2.91</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797614" onclick="win(this.href, 500, 500, 0, 1); return false;">Valenciennes - Nice</a></td><td>2:0 (1:0, 1:0)</td><td class="odds best-betrate">2.01</td><td class="odds">3.11</td><td class="odds">3.90</td><td class="last-cell nobr date">29.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797608" onclick="win(this.href, 500, 500, 0, 1); return false;">Lorient - Marseille</a></td><td>2:1 (1:0, 1:1)</td><td class="odds best-betrate">2.42</td><td class="odds">3.15</td><td class="odds">2.90</td><td class="last-cell nobr date">27.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797613" onclick="win(this.href, 500, 500, 0, 1); return false;">Toulouse - Montpellier</a></td><td>0:1 (0:1, 0:0)</td><td class="odds">2.61</td><td class="odds">3.08</td><td class="odds best-betrate">2.72</td><td class="last-cell nobr date">27.04.2012</td></tr>
- <tr class="rtitle"><th class="left first-cell">33. Round</th><th> </th><th>1</th><th>X</th><th>2</th><th class="nobr last-cell"> </th></tr>
- <tr class="first-row"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797601" onclick="win(this.href, 500, 500, 0, 1); return false;">Lyon - Lorient</a></td><td>3:2 (1:2, 2:0)</td><td class="odds best-betrate">1.52</td><td class="odds">3.90</td><td class="odds">6.25</td><td class="last-cell nobr date">22.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797595" onclick="win(this.href, 500, 500, 0, 1); return false;">Ajaccio - Nancy</a></td><td>0:0 (0:0, 0:0)</td><td class="odds">2.39</td><td class="odds best-betrate">3.10</td><td class="odds">2.98</td><td class="last-cell nobr date">22.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797604" onclick="win(this.href, 500, 500, 0, 1); return false;">Paris SG - Sochaux</a></td><td>6:1 (3:1, 3:0)</td><td class="odds best-betrate">1.34</td><td class="odds">4.58</td><td class="odds">8.79</td><td class="last-cell nobr date">22.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797596" onclick="win(this.href, 500, 500, 0, 1); return false;">Bordeaux - Marseille</a></td><td>2:1 (2:0, 0:1)</td><td class="odds best-betrate">2.34</td><td class="odds">3.08</td><td class="odds">3.10</td><td class="last-cell nobr date">21.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797597" onclick="win(this.href, 500, 500, 0, 1); return false;">Brest - Rennes</a></td><td>0:1 (0:1, 0:0)</td><td class="odds">3.49</td><td class="odds">3.04</td><td class="odds best-betrate">2.17</td><td class="last-cell nobr date">21.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797598" onclick="win(this.href, 500, 500, 0, 1); return false;">Caen - St Etienne</a></td><td>1:4 (0:1, 1:3)</td><td class="odds">2.59</td><td class="odds">3.06</td><td class="odds best-betrate">2.74</td><td class="last-cell nobr date">21.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797599" onclick="win(this.href, 500, 500, 0, 1); return false;">Dijon - Lille</a></td><td>0:2 (0:2, 0:0)</td><td class="odds">4.66</td><td class="odds">3.41</td><td class="odds best-betrate">1.76</td><td class="last-cell nobr date">21.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797600" onclick="win(this.href, 500, 500, 0, 1); return false;">Evian TG - Toulouse</a></td><td>2:1 (1:0, 1:1)</td><td class="odds best-betrate">2.57</td><td class="odds">3.03</td><td class="odds">2.80</td><td class="last-cell nobr date">21.04.2012</td></tr>
- <tr class=""><td class="first-cell tl"><a href="../matchdetails.php?matchid=797602" onclick="win(this.href, 500, 500, 0, 1); return false;">Montpellier - Valenciennes</a></td><td>1:0 (1:0, 0:0)</td><td class="odds best-betrate">1.43</td><td class="odds">4.16</td><td class="odds">7.48</td><td class="last-cell nobr date">21.04.2012</td></tr>
- <tr class="strong"><td class="first-cell tl"><a href="../matchdetails.php?matchid=797603" onclick="win(this.href, 500, 500, 0, 1); return false;">Nice - Auxerre</a></td><td>1:0 (1:0, 0:0)</td><td class="odds best-betrate">2.04</td><td class="odds">3.17</td><td class="odds">3.69</td><td class="last-cell nobr date">21.04.2012</td></tr>
- ...............
|
Mon code Perl est le suivant et mon problème est que le fichier resfrance1.txt est bien créer mais il est vide. Je me demande si ici le module HTML::TreeBuilder est bien adapté, car il n'y a pas de balise <tr> qui encadre le match, le score et la date, c'est très découpé comme code du coup c'est plus compliqué que je pensais. Merci pour vos réponses éclairées.
Code :
- #!C:/Perl/bin/perl.exe -w
- use strict; use warnings;
- use HTML::TreeBuilder;
- use LWP::Simple;
- open(A,">resfrance1.txt" );
- my $url = 'http://www.betexplorer.com/soccer/france/ligue-1/results/';
- my $tree = HTML::TreeBuilder->new_from_content(get($url));
- my @tr = $tree->find('tr');
- foreach (@tr) {
- my @infos = ();
- my $th = $_->look_down("_tag", "th", "class", "left first-cell" );
- next unless ($th);
- my @content = $th->content_list();
- push @infos, $content[0];
- my $td = $_->look_down("_tag", "td", "class", "first-cell tl" );
- next unless ($td);
- my $a = $td->find('a');
- next unless ($a);
- @content = $a->content_list();
- push @infos, $content[0];
- my $td1 = $_->look_down("_tag", "td" );
- @content = $td1->content_list();
- push @infos, $content[0];
- my $td2 = $_->look_down("_tag", "td", "class", "last-cell nobr date" );
- next unless ($td2);
- @content = $td2->content_list();
- push @infos, $content[0];
- print A "@infos\n";
- }
-
- $tree = $tree->delete;
- close A;
|
|