Created
July 23, 2008 19:55
-
-
Save hwatkins/1878 to your computer and use it in GitHub Desktop.
Simple script to find most popular twitpic photos
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 'rubygems' | |
require 'mechanize' | |
require 'hpricot' | |
site="www.twitpic.com" | |
# Grab the highest picture number | |
agent = WWW::Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
page = agent.get("http://#{site}/public_timeline") | |
doc = Hpricot(page.body) | |
#puts doc | |
views = (doc/"/html/body/center/div/div/div[3]/div[2]/table/tr/td[2]/div[2]/a").attr("href").split('/')[1].to_i(36) | |
puts views | |
(1..views).each do |q| | |
i=q.to_s(36) | |
agent = WWW::Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
page = agent.get("http://#{site}/#{i}") | |
doc = Hpricot(page.body) | |
views = (doc/"/html/body/center/div/div/div[2]/div[2]/div[3]/span").inner_html.to_i | |
puts "#{i} #{views}" if views>300 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment