Skip to content

Instantly share code, notes, and snippets.

@jandudulski
Created October 28, 2010 13:03
Show Gist options
  • Save jandudulski/651284 to your computer and use it in GitHub Desktop.
Save jandudulski/651284 to your computer and use it in GitHub Desktop.
na początek. mechanize rox!
#!/usr/bin/env ruby1.9.1
# encoding: utf-8
require 'rubygems'
require 'nokogiri'
require 'mechanize'
def get_password
puts "Password please:"
system "stty -echo"
$stdin.gets.chomp
rescue NoMethodError, Interrupt
exit
ensure
system "stty echo"
end
# init
agent = Mechanize.new
page = agent.get('http://www.charazay.com/')
# login
login_form = page.form('login')
login_form.username = ARGV[0]
login_form.password = get_password
page = agent.submit(login_form)
# players page
page = agent.click(page.link_with(:text => 'Players'))
# players in rows
players = page.parser.xpath("//table[@id='players']/tbody/tr")
# print list of players
players.each do |p|
puts p.xpath("td[2]/a/text()").to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment