simple ruby script to see what pages on a site are Facebook liked

dantex

New member
May 18, 2009
382
14
0
Had to see what pages on a wordpress site had shares/likes. Whipped this out real quick. With more futzing around with the api you can differentiate between likes/shares/comments.

Thought you might like to run it against some of your sites. Enjoy.

Code:
#!/opt/local/bin/ruby

require 'rubygems'
require 'json'
require 'open-uri'
require 'hpricot'

# get urls
sitemap = open(ARGV[0]).read
doc = Hpricot(sitemap)
(doc/'loc').each do |url|
  deep = url.inner_html
  puts deep
  content = open("http://graph.facebook.com/" + deep).read
  puts JSON.parse(content)['shares']
end
 


Nice man, good to see more ruby stuff posted here.

Some fun things/notes:

1) Nokogiri has superceded hpricot as the modern DOM parser for Ruby. hpricot is fine, but nokogiri is just more up to date.

2) you should pull in urls with Mechanize because you can proxy with it. That allows you to hit Facebook more heavily

3) Anemone - Ruby Web-Spider Framework <---you can use that to automatically crawl an entire site to fully automate your script. Punch in domain, get back data.
 
Anemone looks pretty sweet, thanks. I was just running this against wordpress' sitemap.xml so it saved a lot of time. But for something bigger that gem would do the trick. Will file it away.