Witam,
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'
private $phrases = array();
/*
* 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() {
if( count( $this->urls ) > 1
&& count( $this->phrases ) == 1
) self::checkManyURLs();
elseif( count( $this->phrases ) > 1
&& count( $this->urls ) == 1
) 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 )
{
preg_match('@^(?:http://)?([^/]+)@i', $page, $matches); 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 );
for( $i=0
, $il=count( $this->urls ); $i<$il; $i++ ) { $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 ] );
for( $i=0
, $il=count( $this->phrases ); $i<$il; $i++ ) { $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 = new checkPosition
( array( 'http://www.wp.pl' ), array( 'wirtualna polska', 'wydarzenia', 'aktualnosci', 'prognoza pogody', 'wiadomosci z kraju' ) );
$c->getRank();
$wynik = $c->getResults();
Klasa przestała działać (IMG:
style_emoticons/default/exclamation.gif) !
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 (IMG:
style_emoticons/default/smile.gif)
Na pewno powyższa klasa przydała by się wielu osobą (IMG:
style_emoticons/default/smile.gif)