Fast Ruby Script to Check Keyword Rankings, PR, and Backlinks

dchuk

Senior Botter
Oct 30, 2008
7,044
224
0
San Diego,CA
serpiq.com
I'm a Ruby guy, I do PHP a lot as well, but anything that doesn't have to be built for a website should not be in PHP in my opinion. So here's something fun for you all to play with.

This script runs through a csv of keywords and searches the Google SERPs for any pages from that domain. It then connects to Yahoo SE for checking inbound links, and then uses this really interesting Page Rank script I found to find the PR really really fast.

The sweet part about this script is that I set it up to use thread pooling, so you can have a bunch of simultaneous threads running at once which greatly speeds this thing up. I was able to check 1000 serps for 60 keywords with backlinks and PR in about a minute with this, pretty awesome.

When it's done, it spits out a csv with 5 columns for you to view the results.

I tried to comment my code as much as possible, so if you're interested in learning some Ruby, download it and check it out. I don't claim to be a Ruby Ninja though, so don't judge me if I didn't use all the fancy Ruby tricks everywhere. :)

I slapped this together today and figured anyone who can play with Ruby would have some fun playing with it. I programmed it on Ubuntu, with Ruby 1.8.7, so I can't make any guarantees that you can make it work yourself on your machine. If anyone does take the time to download this, grab the gems, and fire it up, post in here so I can see how well this works on other machines.

TO USE IT:

First, you need the following gems:
  • mechanize
  • yahoo-se
  • work_queue
(basic gem rules apply, sudo gem install blahblah)

Second, you need a Yahoo API Key. They're free and easy, it's how you get the backlink analysis. Put that into the variable "yahoo_app_id" in rankings.rb

Third, I built this to use proxies with authorization. If you understood that last sentence and can code Ruby, then go modify googleserps.rb and put your own proxies in there, or strip out the code that deals with proxies if you don't want to use them. It's a really good idea to use proxies though, this thing is (hopefully) fast enough to get your ip banned without them. Just a word of warning.

After that, open up "keywords.csv" and put in your keywords, one per line.

Then from the command line, run "ruby rankings.rb". It should start up and ask your domain (If anyone has some sweet ASCII art, send it my way and I'll plug it in for the splash screen).

It's going to ask your domain, the number of Serp results to dig into (up to 1000), the number of results per page (100), the search delay (in seconds, don't be stupid, at least have it pause for two seconds or something), and the number of threads to run at a time (I haven't benchmarked this to find the right number of threads, so play with it).

After that, it will go beat up Googs and spit out a results CSV file in that same folder. Open that up in a Spreadsheet app and you should be staring at all of your rankings, backlinks, and PR.

Let me know if it works for you all, or if it lights shit on fire or something. Curious to see what others see when using it.

Good luck!
 

Attachments



I'm a Ruby guy, I do PHP a lot as well, but anything that doesn't have to be built for a website should not be in PHP in my opinion. So here's something fun for you all to play with.

This script runs through a csv of keywords and searches the Google SERPs for any pages from that domain. It then connects to Yahoo SE for checking inbound links, and then uses this really interesting Page Rank script I found to find the PR really really fast.

The sweet part about this script is that I set it up to use thread pooling, so you can have a bunch of simultaneous threads running at once which greatly speeds this thing up. I was able to check 1000 serps for 60 keywords with backlinks and PR in about a minute with this, pretty awesome.

When it's done, it spits out a csv with 5 columns for you to view the results.

I tried to comment my code as much as possible, so if you're interested in learning some Ruby, download it and check it out. I don't claim to be a Ruby Ninja though, so don't judge me if I didn't use all the fancy Ruby tricks everywhere. :)

I slapped this together today and figured anyone who can play with Ruby would have some fun playing with it. I programmed it on Ubuntu, with Ruby 1.8.7, so I can't make any guarantees that you can make it work yourself on your machine. If anyone does take the time to download this, grab the gems, and fire it up, post in here so I can see how well this works on other machines.

TO USE IT:

First, you need the following gems:
  • mechanize
  • yahoo-se
  • work_queue
(basic gem rules apply, sudo gem install blahblah)

Second, you need a Yahoo API Key. They're free and easy, it's how you get the backlink analysis. Put that into the variable "yahoo_app_id" in rankings.rb

Third, I built this to use proxies with authorization. If you understood that last sentence and can code Ruby, then go modify googleserps.rb and put your own proxies in there, or strip out the code that deals with proxies if you don't want to use them. It's a really good idea to use proxies though, this thing is (hopefully) fast enough to get your ip banned without them. Just a word of warning.

After that, open up "keywords.csv" and put in your keywords, one per line.

Then from the command line, run "ruby rankings.rb". It should start up and ask your domain (If anyone has some sweet ASCII art, send it my way and I'll plug it in for the splash screen).

It's going to ask your domain, the number of Serp results to dig into (up to 1000), the number of results per page (100), the search delay (in seconds, don't be stupid, at least have it pause for two seconds or something), and the number of threads to run at a time (I haven't benchmarked this to find the right number of threads, so play with it).

After that, it will go beat up Googs and spit out a results CSV file in that same folder. Open that up in a Spreadsheet app and you should be staring at all of your rankings, backlinks, and PR.

Let me know if it works for you all, or if it lights shit on fire or something. Curious to see what others see when using it.

Good luck!
+rep, you're the fucking man
let's get a beer tonight? hit me up
 
Looks cool. Haven't played with it much, but I did need to install 2 more gems to get it to run:

fastercsv
json
 
You sir are correct. My bad. Other than that did it run alright for ya?

Its running, but for some reason not saving any results. Its almost assuredly my fault, though. I'll figure it out when I get the chance. Thanks for the share!
 
Two things: one, post up any questions here about what's going on and I'll try and help you out. Two, I accidentily ran this without proxies earlier and got Google banned in like 3 minutes flat on a big keyword list. Be careful.
 
would rep if I could, thanks for the share. I looked at coding up a few scrapers in ruby before but in the end just went back to php as I didn't feel like learning a new language and ruby has a steep learning curve I heard. I dl and look at the code myself later.
 
+rep thanks for the share. I looked at coding up a few scrapers in ruby before but in the end just went back to php as I didn't feel like learning a new language and ruby has a steep learning curve I heard. I dl and look at the code myself later.

Ruby as a language doesn't have a steep learning curve, it just has some unique syntax and things that aren't used in PHP like blocks (you'll see them in my code, they look like array.each do |a| {}).

Rails has a bad learning curve. Actually, any time you want to use Ruby to serve up a website, you step away from the drag and drop ease of PHP. I stick to PHP for website stuff, but I'm thinking about using Sinatra for some smaller projects.

For scraping though, Ruby is pretty fun :338:
 
Ruby as a language doesn't have a steep learning curve, it just has some unique syntax and things that aren't used in PHP like blocks (you'll see them in my code, they look like array.each do |a| {}).

Rails has a bad learning curve. Actually, any time you want to use Ruby to serve up a website, you step away from the drag and drop ease of PHP. I stick to PHP for website stuff, but I'm thinking about using Sinatra for some smaller projects.

For scraping though, Ruby is pretty fun :338:

Sinatra is a nice framework, though once you throw in ActiveRecord and HAML you ask yourself "why didn't I just use Rails and get the helpers?" :P

I must say that Ruby has become my favourite language. Rails makes web programming fun again, and the Ruby language is close enough to Perl to make it useful, and doesn't have the write-only characteristics that Perl does.

Sean