como vamos utilizar mais no futuro, vou liberar aqui de uma vez algumas classes que fiz..
busca no Google
function getGoogle($string,$pages=1) {
$num = 100; $start = 0; $buffer = "";
do {
$handle = fopen("http://www.google.com.br/search?&q=allinurl:$string&num=$num&start=$start",'r');
while(!feof($handle)) {
$buffer .= fread($handle, 8192);
if(eregi("We're sorry...",$buffer)) {
fclose($handle);
break 2;
}
}
fclose($handle);
if($pages > 1) {
$start += 100;
}
sleep(5);
} while(--$pages);
$content = getLinks($buffer);
return $content;
}
busca no cadê
function getCade($string,$pages=1) {
$num = 100; $start = 1; $end = 1;
$buffer = "";
do {
$handle = fopen("http://cade.search.yahoo.com/search?&p=inurl:$string&n=$num&start=$start&b=$end",'r');
if($handle == false) {
break 1;
}
while(!feof($handle)) {
$buffer .= fread($handle, 8192);
if(eregi("erro 999",$buffer)) {
fclose($handle);
break 2;
}
}
fclose($handle);
if($pages > 1) {
$end += 100;
}
sleep(5);
} while(--$pages);
$content = getLinks($buffer);
return $content;
}
busca no live.com
function getLive($string,$pages=1) {
$num = 11; $buffer ="";
do {
$handle = fopen("http://search.live.com/results.aspx?q=$string&scope=&first=$num",'r');
while(!feof($handle)) {
$buffer .= fread($handle, 8192);
}
fclose($handle);
if($pages > 1) {
$num += 10;
}
} while(--$pages);
$content = getLinks($buffer);
return $content;
}
É importante observar que essas funções não formatam oque você procura, então se for querer links por exemplo, desenvolvi essa função:
function getLinks(&$buffer) {
preg_match_all('/href="([^"> ]*)/',$buffer,$matches);
foreach($matches[1] as $value) {
if(eregi(".",$value) && !preg_match('/(google|orkut|live\.com|cade)/',$value)) {
$matches_pure[] = $value;
}
}
unset($matches);
unset($buffer);
foreach($matches_pure as $key => $value) {
if(preg_match('/^\//',$value)) {
unset($matches_pure[$key]);
}
elseif(preg_match('/^http/',$value) == 0 && preg_match('/^https/',$value) == 0) {
$matches_pure[$key] = 'http://' . $value;
}
}
$links = array();
foreach($matches_pure as $value) {
preg_match('/https?:\/\/[^\/]*/',$value,$first_step); $second_step = preg_split('/https?:\/\/[^\/]*/',$value); $host = preg_replace('/https?:\/\//','',$first_step[0]);
$url = $second_step[1];
$links[$host] = $url;
}
unset($matches_pure);
return $links;
}
Criei um outro tópico com um exemplo legal da utilização dessas funções, procurem por Scan Rpc.
Até