Por hay buscando en google me encontré varias clases, dejo una:
Código PHP:
Ver original<?php
/**
* This class crawls google and find out on which page a website is lisited, based on the keyword searched.
*
* @see This class does NOT calculated the Google Page Rank
*/
class PhpKeywordAnalyser {
private $website="";
private $keyword="";
private $url="";
private $start=0;
private $page=false;
private $records=false;
/**
* Function to pre process and store the values of Keyword and Website
*
* @param string $keyword
* @param string $website
* @return resource
*/
public function __construct($keyword, $website){
}
}
$this->website=$website;
$this->keyword=trim($keyword); $this->enableVerbose=$enableVerbose;
$this->url=$this->updateUrl($keyword, $this->start);
}
/**
* This function starts the crawling process and it verbose the content as it goes to next page.
*
* @return string [buffer]
*/
public function initSpider(){
echo "<p>Searching: <b>".$this->keyword."</b> and Looking for: <b>".$this->website."</b></p>";
$i=10;
$c=1;
while($c<=10) {
echo "<ul><li><b>Searching in Page: $c</b></li>";
$records= $this->getRecordsAsArray($this->url);
echo "<ul>";
for($k=0;$k<$count;$k++){
$j=$k+1;
$link=$records[$k][2];
if($this->website==$link){
$domain=$this->website;
echo "<li><h1>Result was found in Page: $c and Record: $j</h1></li>";
echo "<div>Congrats, We searched google's top 10 pages for <b>\"".$this->keyword."</b>\", we found your domain <b>\"$domain\"</b> listed on page: $c at $j place </div>";echo "</ul></ul>";
}
else{
echo "<li>Result not found on Page: $c and Record: $j</li>";
}
}
echo "</ul></ul>";
$c++;
$this->updateUrl($this->keyword, $i);
}
echo "Crawled through all 10 pages.";
if($this->page==false){
$domain=$this->website;
$keyword=$this->keyword;
echo "<div>Sorry, We searched google's top 10 pages for <b>\"$keyword\"</b>, but was unable to find your domain <b>\"$domain\"</b> listed anywhere. </div>";
}
else {
$page=$this->page;
$records=$this->records;
$domain=$this->website;
$keyword=$this->keyword;
echo "<div>Congrats, We searched google's top 10 pages for <b>\"$keyword\"</b>, we found your domain <b>\"$domain\"</b> listed on page: $page at $record place </div>";
}
}
/**
* Function to get records as an array.
*
* @access private
* @param string $url
*
* @return array
*/
private function getRecordsAsArray($url){
$pattern='/<div class="s"(.*)\<cite\>(.*)\<\/cite\>/Uis';
$html=$this->getCodeViaFopen($url);
return $matches;
}
/**
* Function to update the google search query.
*
* @access private
* @param string $keyword
* @param string $start
*
* @return string
*/
private function updateUrl($keyword, $start){
$this->start=$this->start+$start;
return "http://www.google.com/search?start=".$this->start."&q=$keyword";
}
/**
* Function to get HTML code from remote url
*
* @access private
* @param string $url
*
* @return string
*/
private function getCodeViaFopen($url){
$returnStr="";
$fp=fopen($url, "r") or
die("ERROR: Invalid search URL"); }
return $returnStr;
}
}
$keyword="Google";
$website="www.google.com";
// optional for accepting parameters from Query string
if(isset($_GET['keyword'])) { $keyword=$_GET['keyword']; } if(isset($_GET['website'])) { $website=$_GET['website']; }
$phpKeywordAnalyser = new PhpKeywordAnalyser($keyword, $website);
$phpKeywordAnalyser->initSpider();
En
http://www.phpclasses.org/ hay varias parecidas para que saques ideas.
Aclaro que la clase es gracias a Rochak Chauhan
License: Free For Educational Use
Saludos: