Umieszczam gotową klasę która przestała działać:
<?php class checkPosition { const G_PATTERN = '/<h3 class="r"><a href="([^"]+)">/'; private $limit = 100; private $lang = 'pl'; private $dc = 'www.google.pl'; private $format = 'array'; //or 'json' /* * Contains results */ public function setLimit( $limit ) { $this->limit = $limit; } /* * Sets language (param hl=in google query) */ public function setLang( $lang ) { $this->lang = $lang; } /* * Sets DC (it can be url or IP) */ public function setDC( $dc ) { $this->dc = $dc; } /* * Sets returned format */ public function setFormat( $format ) { $this->format = $format; } public function getRank() { self::checkManyURLs(); self::checkManyPhrases(); else } /* * gets host from URL * @param $page (String) - url e.g. <a href="http://example.com" target="_blank">http://example.com</a> * @return (String) - host e.g. "example.com" */ private function getHost( $page ) { return $matches[1]; } /* * Send request to Google server * @param $url (String) - google query url * @return (Array) - array with results (urls / serp) */ private function sendRequest( $url ) { $c = curl_init(); curl_setopt( $c, CURLOPT_HEADER, 0 ); curl_setopt( $c, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $c, CURLOPT_VERBOSE, 1 ); curl_setopt( $c, CURLOPT_REFERER, $this->dc ); curl_setopt( $c, CURLOPT_URL, $url ); $d = curl_exec( $c ); curl_close( $c ); return $r; } private function checkManyURLs() { $url = 'http://'. $this->dc .'/search?hl='. $this->lang .'&q='. $phrase .'&num='. $this->limit; $this->r['phrase'] = $this->phrases[0]; $r = self::sendRequest( $url ); $ii = 0; $this->r[ $i ]['url'] = $this->urls[ $i ]; $this->r[ $i ]['url_host'] = self::getHost( $this->urls[ $i ] ); $this->r[ $i ]['position'] = 0; for( $p=0; $p<$this->limit; $p++ ) { $sPage = self::getHost($r[$p]); if( $r[($p+1)] ) { $sNext = self::getHost($r[($p+1)]); if( $sDomena != $sNext ) { $ii++; if( $sPage == $this->r[ $i ]['url_host'] ) $this->r[ $i ]['position'] = $ii; } $sDomena = $sNext; } } } } private function checkManyPhrases() { $this->r['url'] = $this->urls[ 0 ]; $this->r['url_host'] = self::getHost( $this->urls[ 0 ] ); $url = 'http://'. $this->dc .'/search?hl='. $this->lang .'&q='. $this->phrases[ $i ] .'&num='. $this->limit; $ii = 0; $r = self::sendRequest( $url ); $this->r[ $i ]['phrase'] = $this->phrases[ $i ]; $this->r[ $i ]['position'] = 0; for( $p=0; $p<$this->limit; $p++ ) { $sPage = self::getHost($r[$p]); if( $r[($p+1)] ) { $sNext = self::getHost($r[($p+1)]); if( $sDomena != $sNext ) { $ii++; if( $sPage == $this->r['url_host'] ) { $this->r[ $i ]['position'] = $ii; break; } } $sDomena = $sNext; } } } } public function getResults() { switch( $this->format ) { case 'array' : return $this->r; case 'json' : return json_encode( $this->r ); } } } //------------------------------------------------------- $c->getRank(); $wynik = $c->getResults();
Klasa przestała działać !
Wiem że google zmienia co jakiś czas swoje struktury, żeby tego typu skrypty przestały działać.
Mógł by ktoś mnie naprowadzić na co mam zwrócić szczególną uwagę i naprowadzić mnie żebym mógł zmodyfikować żeby znów działało
Na pewno powyższa klasa przydała by się wielu osobą