Skip to content

Instantly share code, notes, and snippets.

@tbueno
Created March 11, 2009 18:38
Show Gist options
  • Save tbueno/77639 to your computer and use it in GitHub Desktop.
Save tbueno/77639 to your computer and use it in GitHub Desktop.
require 'mechanize'
require 'hpricot'
class Orkut
def initialize(email, pass)
@agent = WWW::Mechanize.new
@email = email
@pass = pass
end
def print_scraps
page = scrap_page
scraps = page.search "div[@class='mblock']/div"
scraps.each do |l|
parts = Hpricot(l).inner_html.split("\n")
puts "Name: #{parts[1]}"
puts "Date: #{parts[3]}"
puts "Message: "
parts[4..parts.size-2].each {|line| puts line}
puts "-" * 50
end
end
private
def scrap_page
log_in
#Call home page to get the temporary URL that google generates
page = @agent.get "http://m.orkut.com/Home"
#Try to access the temporary URL to pass the authentication token
page = @agent.get page.meta[0].uri.to_s
#Now, with authentication ready we can access the content
page = @agent.get "http://m.orkut.com/Scrapbook"
end
def log_in
page = @agent.get "https://www.google.com/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fm.orkut.com%2FRedirLogin%3Fmsg%3D0%26page%3Dhttp%253A%252F%252Fm.orkut.com%252FHome&cd=US&nui=5&btmpl=mobile&ltmpl=mobile&passive=true&skipvpage=true&sendvemail=false"
form = page.forms.first
form.Email = @email
form.Passwd = @pass
page = @agent.submit form
end
end
o = Orkut.new('[email protected]', 'your_pass')
o.print_scraps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment