Skip to content

Instantly share code, notes, and snippets.

@xdite
Created December 17, 2009 12:57
Show Gist options
  • Save xdite/258721 to your computer and use it in GitHub Desktop.
Save xdite/258721 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
site = ARGV[0]
doc = Nokogiri::HTML(open("http://www.alexa.com/siteinfo/#{site}"))
data = []
doc.css('ul')[4].css('li.geo_percentages').each_with_index do |raw,i|
raw.css('span.geo_country').each do |country_raw|
country = country_raw.search('a').first['href'].gsub("/topsites/countries/","")
data[i] = ["#{country}"]
end
raw.css('span.geo_number').each do |c|
data[i] << c.content
end
end
puts Date.today
puts data.inspect
xdite:~ pixnet$ ruby alexa.rb belovely.tw
2009-12-17
[["TW", "4,096"], ["HK", "44,196"], ["MY", "88,085"]]
xdite:~ pixnet$ ruby alexa.rb murmur.tw
2009-12-17
[["TW", "1,132"], ["HK", "8,214"], ["CN", "42,178"], ["CA", "153,678"], ["US", "299,925"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment