<?php /** * This class crawls google and find out on which page a website is lisited, based on the keyword searched. * * @author Rochak Chauhan <rochakchauhan@gmail.com> * @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->enableVerbose=$enableVerbose; } /** * This function starts the crawling process and it verbose the content as it goes to next page. * * @return string [buffer] */ public function initSpider(){ $i=10; $c=1; while($c<=10) { $records= $this->getRecordsAsArray($this->url); // print_r($records); for($k=0;$k<$count;$k++){ $j=$k+1; $link=$records[$k][2]; if($this->website==$link){ $domain=$this->website; 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>"; exit; } else{ } } $c++; $this->updateUrl($this->keyword, $i); } 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); // print_r($matches); 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.pl/search?q=$keyword&hl=pl&lr=&start=".$this->start."&sa=N"; } /** * Function to get HTML code from remote url * * @access private * @param string $url * * @return string */ private function getCodeViaFopen($url){ $returnStr=""; } return $returnStr; } } ?>
uzycie:
<?php $keyword="programy"; $website="pobieraj24.pl"; // optional for accepting parameters from Query string require_once("PhpKeywordAnalyser.inc.php"); $phpKeywordAnalyser = new PhpKeywordAnalyser($keyword, $website); $phpKeywordAnalyser->initSpider(); ?>
ten skrypt działa, jezeli jest dana strona na pierwszej stronie a jak zrobić, żeby jak np cos jest dalej w wynikach czyli na drugiej albo 3 stronie to żeby wyswietlało, że się tam znajduje bo tak to ciągle sprawdza tylko pierwszą strone w kółko.jak zrobić, żeby dodawało +10 do $this->start i tak za kazdym przejsciem pętli?