Showing posts with label Google Tech. Show all posts
Showing posts with label Google Tech. Show all posts

Friday, 27 February 2009

Simple PHP Multi Keyword Google Rank Checker

0 comments
I had a couple of commenters on my post about the Google Blogsearch URL Scraper ask whether it could be turned into a google rank checking script.
Well, in a nutshell, the answer to that question was no, but that’s not to say that the Pimp didn’t have one in his arsenal, and that he’d be prepared to share it!
So here it is, and as always, for those who want to know how it works, the code is extremely well commented (you’re going to need to go in and replace all the single and double quotes after you’ve copied the code below, as wordpress screws them up (or download the script here):
ob_start();
//put your site’s URL here, but leave off the http://www
$url = “pimpmypagerank.com”;
//put all the keywords you want to check here, make sure you leave the single quotes and commas intact for each keyword
$keywords = array(
‘google scraper’,
‘php script to get pagerank’,
‘Simple PHP Google Bot Cloaking Script’,
);
//Just tells us what URL we’re checking rankings for
echo “

Google SERPS For ” .$url. “

”;
//start to run through each of the keywords
foreach($keywords as $keyword) {
//set our counter at zero, so we can work out what the ranking of the page
$count = 0;
//make a URL that we can query Google with
$search = “http://www.google.com/search?q=” .urlencode($keyword). “&num=100″;
//now go get that page
$google = file_get_contents($search);
//funky regular expression stuff to find our URL in the results
$description= (’/<h3 class=r><a href=\”(.+?)\” class=l/’);
preg_match_all($description,$google,$match);
//start looping through each of the results on the page
foreach( $match[1] as $value){
//Add one to the counter after we check each of the results
$count = $count + 1;
//check each of the 100 results from google, to see if our URL is in it.
if(strstr($value, $url)) {
//if this particular result has our URL in it, print it to the page, along with the ranking ($count variable from above)
echo $keyword. ” - ” .$count. “
”;
ob_flush();
flush();
}
}
//Have a bit of a rest before we go check the next keyword, so we don’t get booted from the Goog’
sleep(rand(30,60));
}
?>
And there you have it!
Tomorrow, the same script, but to get Yahoo! results…

PHP Google Blog Search URL Scraper

0 comments
Sometimes you just need a crapload of URL’s from Wordpress blogs. It’s nobodies business why you need them, if you need them, you need them.
Enter DaPimp’s Google Blogsearch URL scraper.
In a nutshell, this script grabs the fist 1,000 results of Wordpress blogs for a given keyword, and spits them out in a nice list for you.
**You’ll need PHP5, and a server with cURL enabled for this script to work**
Instructions for use:
You can either download the script here (change the file extension to .php), or just copy and paste the code below (wordpress buggers up the quote marks in code, so you’ll probably need to go and replace them manually -just download the script, it’s much easier)
Open the script in a text editor, and change the $keyword variable at the top to the keyword you want to search for
Save the script and upload it to your server
Navigate to the script in your browser, and wait, you’ll get your list
============ Start PHP Script ================
//give the script a keyword to search for
$keyword = “ipod touch”;
$keyword = str_replace(” “, “+”, $keyword);
//start a counter so we can number our results
$num = 0;
//set a start for our paging of Google Blogsearch (we’re going to be getting 10 pages X 100 results)
$start = 0;
do {
//Create the feed URL we’re going to get from Google Blogsearch
$feed = ‘http://blogsearch.google.com/blogsearch_feeds?hl=en&q=%22′ .$keyword. ‘+%22powered+by+wordpress%22&ie=utf-8&num=100&start=’ .$start. ‘&output=rss’;
//We’re using cURL to actually go fetch the page from Google Blogsearch
$ch = curl_init($feed);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $feed);
$page = curl_exec($ch);
curl_close($ch);
//Loop through the feed, and suck out the URL’s
$xml = new SimpleXMLElement($page);
foreach ($xml->channel->item as $item) {
//Add 1 to our counter, so our list has numbers next to the URL’s
$num = $num + 1;
$link = $item->link;
//Print our shit to the page
echo $num. ‘ - ’ .$link. ‘
’;
}
//Have a rest so we don’t get banned for hitting Google too hard and fast
sleep(30);
//Add 100 to the start, so we can fetch the next 100 results
$start = $start + 100;
}
//Keep doing this shit until we get to page 10 of the Google results
while ($start < 1000);
?>
============ End PHP Script ================

Labels

 

Copyright © 2009 by Free Blogger Themes. Revolution 2 Church Theme by Brian Gardner. Converted into Blogger Template by Bloganol dot Com