Skip to content

Instantly share code, notes, and snippets.

@heukirne
Created July 30, 2013 12:51
Show Gist options
  • Save heukirne/6112617 to your computer and use it in GitHub Desktop.
Save heukirne/6112617 to your computer and use it in GitHub Desktop.
Crawler iCarros.com.br
<?php
$link = mysql_connect("mysql07.host.org", "user", "pwd")
or die("Nao foi possivel conectar");
mysql_select_db("gemeos16",$link) or die("Nao foi possivel selecionar o banco de dados");
mysql_query("set wait_timeout = 7200");
$addr = "http://www.icarros.com.br/volkswagen/gol/ficha-tecnica?versao=";
for($i=15000;$i<17000;$i++){
if (@$html = file_get_contents($addr.$i)) {
preg_match_all("/intertitulo[^>]*>([^<]*)/",$html, $list);
$nome = $list[1][0];
preg_match_all("/sugerido[^>]*>([^<]*)/",$html, $list);
@$valor = preg_replace(array('/R\$\s/','/\./','/,/'),array('','','.'),$list[1][0]);
preg_match_all("/ncia\s\(cv[^>]*>[^<]*\<[^<]*\<[^<]*\<[^>]*>([^<]*)/m",$html, $list);
$potencia = trim(str_replace("\n",'',$list[1][0]));
//echo "$nome , $valor, $potencia\n";
if (is_numeric($potencia)&&is_numeric($valor)) {
$sql = "INSERT INTO iCarros SET idCarro=$i, nome='$nome', valor=$valor , potencia=$potencia, relacao=".($valor/$potencia);
if(!mysql_query($sql)) echo mysql_error();
}
} else {
$erroHandle = error_get_last();
//print_r($erroHandle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment