evo ja sam nedavno se igrao na tu temo i pravio jedan prost parser pa vidi jel ti odgovar ti ga naravno modifikuj za svoju upotrebu
Naravno vazno je da znas sta skidas i sta ti treba da parsujes. Tacnije koji tacno tag te interesuje. Meni je u ovom primeru bilo trazeno da izvucem vrednos izmedju <status> tagova pri tom se zna da ima tacno jedan <status> tag
Code:
$URL="$url?$parsingParameters";
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://$URL");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$html_strana= "";
$html_strana = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
list($pre,$posle) = explode("<status>", $html_strana);
list($vrednost,$posle) = explode("</status>", $posle);
return $vrednost;
Mozes da iskoristis ovaj kod gore sa malom modifikacijom da ti samo vraca sorce html strane pa da posle ti obradjujes source. to moze recimo daizgleda ovako
Code:
<?php
function PassParametersToServer($url, $parsingParameters){
/* $url = web page location. Pass it without http:// */
/* $parsingParameters = Getparameters. Pass it without ? */
/* example:
$url = "www.example.com"
$parsingParameters = "name=Dzo%20Hamilton&location=Los%20Angeles"
*/
$URL="$url?$parsingParameters";
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://$URL");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$html_strana= "";
$html_strana = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
return $html_strana;
}
?>
<form name=form1 action=<?php echo "\"".$_SERVER['PHP_SELF']."\"";?> method=post>
<input type=text name=urlStrana value="www.test.com" size=100 style="background-color:336699; color:FFFFFF;">
<input type=submit name=submit value="Start conversion">
</form>
<?php
$urlstrana = "";
if(isset($_POST['urlStrana'])) $urlstrana = "http://".$_POST['urlStrana'];
echo "Encoded page: $urlstrana<br>";
echo "<br>---------------------------------<BR><BR><BR><BR>";
if(isset($_POST['urlStrana']))
//PassParametersToServer($_POST['urlStrana'], "");
echo "<br>---------------------------------<BR><BR><BR><BR>";
$test_kod = PassParametersToServer($_POST['urlStrana'], ""));
$html_strana = $test_kod;
$stani = false;
for($i=0; $i<strlen($html_strana); $i++){
if($html_strana[$i]== "<") {$stani = false;
if($html_strana[$i+1]=='t' && $html_strana[$i+2]=='r')echo "<br>";
if($html_strana[$i+1]=='t' && $html_strana[$i+2]=='d')echo "|";}
if($html_strana[$i]== ">") { if($html_strana[$i+1]!= "<") {$stani = true; $i++;} }
if($stani){
if($html_strana[$i]== " ") echo " ";
echo "
{$html_strana[$i]}
";
}
}
?>
Ovaj kode
Code:
for($i=0; $i<strlen($html_strana); $i++){
if($html_strana[$i]== "<") {$stani = false;
if($html_strana[$i+1]=='t' && $html_strana[$i+2]=='r')echo "<br>";
if($html_strana[$i+1]=='t' && $html_strana[$i+2]=='d')echo "|";}
if($html_strana[$i]== ">") { if($html_strana[$i+1]!= "<") {$stani = true; $i++;} }
if($stani){
if($html_strana[$i]== " ") echo " ";
echo "
{$html_strana[$i]}
";
}
}
ce te resiti samo nekih tagova ti sad sam koriguj kako tebi odgovara. Funkciju mozes da prekopiras.
A da umalo da zaboravim mora da omogucis curl.