Last active
August 29, 2015 14:15
-
-
Save pabletecodes/58eacc2b40de39aaeda9 to your computer and use it in GitHub Desktop.
A rake task to extract valuable SEO information from a set of URLs
This file contains hidden or 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
http://www.google.com | |
--------------------- | |
TITLE: Google | |
LANG: es | |
DESCRIPTION: Google.es permite acceder a la información mundial en castellano, catalán, gallego, euskara e inglés. | |
KEYWORDS: |
This file contains hidden or 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 'mechanize' | |
task :seo do | |
urls = [ | |
'http://www.google.com' | |
] | |
mechanize = Mechanize.new | |
urls.each do |url| | |
mechanize.get(url) do |page| | |
title = page.title | |
description_tag = page.at('meta[name="description"]') | |
keywords_tag = page.at('meta[name="keywords"]') | |
html_tag = page.at('html') | |
puts "\n#{url}" | |
puts '-' * url.size | |
puts "TITLE: #{title.strip}" | |
puts "LANG: #{html_tag['lang']}" | |
puts "DESCRIPTION: #{description_tag && description_tag[:content]}" | |
puts "KEYWORDS: #{keywords_tag && keywords_tag[:content]}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment