J'ai un tableau généré en html sous la forme suivante:
<tr class="two">
<td width=75%>
<span class="intitule">RIMM ECC PC800 512Mo</span>
</td>
<td align=center class="old">
<span class="prixeuro">inconnu €</span>
</td>
<td align=center>
<span class=textepetit>Plus en vente</a>
</td>
</tr>
Et bis repetita avec <tr class="one">... ce en alternance une ligne sur deux entre "two" et "one" sur x lignes au total.Je n'arrive pas à parser correctement avec des regexp en php et ca me gave...
J'ai bien tenté avec cette routine mais 1) ca me retourne n'importe quoi ou rien et 2) ca ne lit pas ligne par ligne suivant $count...
// ouverture page html distante
$url = "lien html";
$file = @fopen($url, 'r');
$contents = file_get_contents($url);
//comptage de lignes contenant "two" et "one"
$word_array = explode("<tr class=\"two\">", $contents);
$word_array2 = explode("<tr class=\"one\">", $contents);
//addition des deux comptages
$count = count($word_array)+count($word_array2);
//suivant le nombre de lignes $count
for ($i=0; $i<$count; $i++)
{
// On test si le fichier existe ou non
if ($file)
//Si il exite on commencer à parser la page et récupérer les données
{
// on parse suivant la première colonne du tableau
$matches1 = array();
// recherche ce qu'il y a entre <span class="intitule">......</span>
preg_match_all('#(\<span\sclass\=\"intitule\"\>)(.*?)(\<\/span\>)#si', $contents, $matches1,PREG_PATTERN_ORDER);
$intitule = $matches1[$i][1];
// on parse suivant la deuxième colonne du tableau
$matches2 = array();
// recherche ce qu'il y a entre <span class="prixeuro">......</span>
preg_match_all('#(\<span\sclass\=\"prixeuro\"\>)(.*?)(\<\/span\>)#si', $contents, $matches2,PREG_PATTERN_ORDER);
$prixeuro = $matches2[$i][1];
// on parse suivant la troisième colonne du tableau
$matches3 = array();
// recherche ce qu'il y a entre <span class=textepetit>......</span>
preg_match_all('#(\<span\sclass\=textepetit\>)(.*?)(\<\/span\>)#si', $contents, $matches3,PREG_PATTERN_ORDER);
$textepetit = $matches3[$i][1];
// affiche pour voir
echo "Intitulé: ".$intitule." Prix enro: ".$prixeuro." Prix neuf: ".$textepetit."<br/>"; // Pour test
}
// incrément pour changer de ligne
$id++;
}
fclose($file);
Mon source n'est pas forcément propre ou bien construit et il y a sûrement du dom à utiliser mais j'ai pas encore lu la doc dom et franchement j'ai déjà du mal sans...Bon en attendant, ca me retourne:
Si quelqu'un a une idée, je suis preneur et le remercie par avance!Intitulé: >> Prix enro: inconnu € Prix neuf:
Intitulé: >> Prix enro: Prix neuf:
Intitulé: Prix enro: inconnu € Prix neuf:
Intitulé: Prix enro: Prix neuf:
Intitulé: Prix enro: Prix neuf:
Intitulé: Prix enro: Prix neuf:
Intitulé: Prix enro: Prix neuf:
ect...
Cdt.