1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <?php
// Récupérer code source HTML de la page web
$url = "http://www.parisbouge.com/events/2012/05/01/";
$html = file_get_contents($url);
$html = "<<<EOS".$html."EOS";
// Compter nombre d'évènements
$event = '<li class="nom">';
$nb_event=substr_count($html,$event);
echo "il y a : ".$nb_event. "event";
// Construction du pattern
$pattern='`<div id="tab-soiree".*?';
$i=0;
while($i<($nb_event-50)){
$pattern .='<li class="nom">.*?<a href="([^"]+)">([^<]+)</a>.*?<li class="lieu".*?>(<a href=".*?">)?([^<]+).*?';
$i++;
}
$pattern .='`si';
// Execution du pattern
preg_match($pattern, $html, $out);
// Afficher les résultats
$i=1;
while($i<($nb_event*3)){
if(count($out)) {
$url=$out[$i];
$nom=$out[$i+1];
$lieu=$out[$i+3];
echo "<br/>url : $url nom : $nom lieu : $lieu";
}
else {
echo 'Pas trouvé.';
}
$i= $i +4;;
}
?> |
Partager