Sunday, April 24, 2011

Google Ruby Script

My friend coded this for our team. It will take a google search query, and parse out the returned URLs one on a line. It comes in handy for scripting recon on a client. Obviously you need the nokogiri gem installed.
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'

# Perform a google search
# Add numbers in increments of 10 to the array to search more pages
[0].each do |num|
doc = Nokogiri::HTML(open('http://google.com/search?q=' + ARGV[0].to_s + '&start='+num.to_s))
puts "Scrubbing Google for good-ness"
doc.xpath('//h3/a[@class="l"]').each do |link|
temp = link.attribute("href")
puts temp
end

end
I hope you find it useful...

No comments:

Post a Comment