Ok so nobody really wants a full blown tool to check their stats on Google, Yahoo, and Alexa.
But I figured that since I looked for something like this quite a while ago I’d give you guys some small functions to use in whatever scripts you’re building so you can grab backlink numbers, pages indexed and Alexa ranking.
It might save someone some time trying to figure out the regex etc..
It’s not the be all and end all, but it works and does the job.
It goes out and grabs:
- Google Inlinks amount
- Google Backlinks amount
- Yahoo Inlinks amount
- Yahoo Backlinks amount
- Alexa Ranking
If it stops working, don’t blame me, the SE’s quite often change their layouts, but put a comment on this post and I might have a quick look and post an update.
For those of you familiar with curl, you can probably swap out the ‘file_get_contents’ in favour of using the Curl library with Proxy attached in order to avoid getting your IP blocked. Although you’d have bad data due to different country specific IP’s.
It should be fine without if you don’t use it too much.
Enjoy!
function googleindexed($domain) {
$results='';
$query="http://www.google.com/search?q=site:".urlencode($domain)."";
$results=file_get_contents($query);
preg_match("/About (.+?) results/", strip_tags($results), $match);
if(isset($match) && isset($match[1])) {
$sub_google = $match[1];
}else{
$sub_google='0';
}
return $sub_google;
}
function googlebls($domain) {
$results='';
$query="http://www.google.com/search?q=link:".urlencode($domain)."";
$results=file_get_contents($query);
preg_match('/<div id=resultStats>(.+?) result/ism', $results, $match);
if(isset($match) && isset($match[1])) {
$sub_google=str_replace('About ','',$match[1]);
}else{
$sub_google = '0';
}
return $sub_google;
}
function yahooindexed($domain) {
$results='';
$query="http://siteexplorer.search.yahoo.com/siteexplorer/search?ei=UTF-8&p=".urlencode($domain)."&bwm=p&bwms=p&searchbwm=Explore+URL";
$results=file_get_contents($query);
preg_match("/Pages \((.+?)\)/", strip_tags($results), $match);
@$matchtrimmed=array_walk($match,'trim_value');
if(isset($match) && isset($match[1])) {
$tmp=str_replace("about","",$match[1]);
$sub_yahoo = trim($tmp);
}else{
$sub_yahoo=0;
}
return $sub_yahoo;
}
function yahoobls($domain) {
$results='';
$query="http://siteexplorer.search.yahoo.com/siteexplorer/search?ei=UTF-8&p=".urlencode($domain)."&bwm=p&bwms=p&searchbwm=Explore+URL";
$results=file_get_contents($query);
preg_match("/Inlinks \((.+?)\)/", strip_tags($results), $match);
if(isset($match) && isset($match[1])) {
$tmp=str_replace("about","",$match[1]);
$sub_yahoo = trim($tmp);
}else{
$sub_yahoo=0;
}
return $sub_yahoo;
}
function alexa($domain){
$results = '';
$query = 'http://www.alexa.com/siteinfo/'.$domain;
$results=file_get_contents($query);
preg_match('%<img src="/images/icons/globe-sm.jpg" alt="Global" style="margin-bottom:-2px;"/>(.+?)</div>%ism', $results, $match);
if(isset($match) && isset($match[1])) {
$sub_alexa = trim($match[1]);
}else{
$sub_alexa=0;
}
return $sub_alexa;
}
