Mechanize in Ruby

# me.rb - use mechanize from ruby
 
require 'mechanize'
 
# to use Ruby logger uncomment block with Logger.new
agent = WWW::Mechanize.new #{|a| a.log = Logger.new(STDERR) }
page = agent.get('http://mail.yahoo.com')
page.methods.each { |meth|
	puts meth if (!meth.grep(/form/).empty?)
}
onceOnly = 0
puts page.forms[0].methods.sort

Another example

require 'mechanize'
require 'pp'
 
url = 'http://mail.yahoo.com'
agent = WWW::Mechanize.new #{|a| a.log = Logger.new(STDERR) }
page = agent.get(url)
form = page.forms[0]
(0...form.fields.size).each { |indx|
    field = form.fields[indx]
    p field.name
}

rubymechanize.txt · Last modified: 2014/10/26 01:52 (external edit)
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0