Created
December 25, 2013 06:07
-
-
Save mtasuandi/8120579 to your computer and use it in GitHub Desktop.
Google Rank Checker - Yelp.com Perform google search using site:yelp.com biz city category rating:rating(3.0) then return top ten results.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author: M Teguh A Suandi | |
* @company: Biztech Indonesia (http://biztechindonesia.com) | |
* @email: teguh.andro@gmail.com | |
*/ | |
if(@ini_set('max_execution_time', 1200) !== FALSE) | |
@ini_set('max_execution_time', 1200); | |
if(!class_exists('GoogleRankChecker')){ | |
class GoogleRankChecker{ | |
public $start; | |
public $end; | |
public function __construct($start=1, $end=1){ | |
include_once('simple_html_dom.php'); | |
$this->start = $start; | |
$this->end = $end; | |
} | |
public function find($city, $category, $rating){ | |
for($start=($this->start-1)*10; $start<=$this->end*10; $start+=10){ | |
$kcity = str_replace(" ", "+", trim($city)); | |
$kcategory = str_replace(" ", "+", trim($category)); | |
$krating = trim($rating); | |
$kkeyword = 'site:yelp.com'.' biz '.$kcity.' '.$kcategory.' rating:'.$krating; | |
$keyword = str_replace(" ", "+", $kkeyword); | |
$url = "https://www.google.com/search?ie=UTF-8&q=$keyword&start=$start"; | |
$html = file_get_html($url); | |
foreach($html->find('h3') as $elementh3){ | |
foreach($elementh3->find('a') as $element){ | |
$pos1 = strpos($element->href, '/aclk?'); | |
$pos2 = strpos($element->href, 'http://www.yelp.com/c/'); | |
if($pos1 === false && $pos2 === false){ | |
$ylink[] = $element->href; | |
} | |
} | |
} | |
} | |
array_splice($ylink, 10); | |
foreach($ylink as $yeah){ | |
parse_str($yeah, $output); | |
$fyelplink[] = $output['/url?q']; | |
} | |
return $fyelplink; | |
} | |
private function _isCurl(){ | |
return function_exists("curl_version"); | |
} | |
public function _curl($url){ | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, true); | |
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 120); | |
curl_setopt($ch, CURLOPT_MAXREDIRS, 10); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_SSLVERSION, 3); | |
$content = curl_exec($ch); | |
$errno = curl_errno($ch); | |
$error = curl_error($ch); | |
curl_close($ch); | |
return $content; | |
if($errno == 0){ | |
return $content; | |
} | |
else{ | |
return array("errno" => $errno, "errmsg" => $error); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment