Created
February 16, 2009 22:29
-
-
Save newbamboo/65420 to your computer and use it in GitHub Desktop.
Check if the links Google has indexed on your actually work
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
require 'rubygems' | |
require 'open-uri' | |
require 'hpricot' | |
links = [] | |
(1..12).each do |page| | |
offset = (page * 10) - 10 | |
url = "http://www.google.com/search?hl=en&client=safari&rls=en-us&q=site:blog.new-bamboo.co.uk&start=#{offset}&sa=N" | |
document = Hpricot(open(url)) | |
cite_tags = document.search('cite') | |
cite_tags.each do |cite| | |
link, junk = cite.inner_html.split(/\s/) | |
link = "http://#{link}" | |
links << link | |
end | |
end | |
links.sort! | |
links.each do |link| | |
begin | |
open(link) | |
rescue OpenURI::HTTPError | |
puts link | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment