Differences

This shows you the differences between two versions of the page.

Link to this comparison view

rubymechanize [2014/10/26 01:52] (current)
Line 1: Line 1:
 +===== Mechanize in Ruby =====
 +<code 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
 +
 +</​code>​
 +
 +''''​Another example ​
 +<code ruby>
 +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
 +}
 +</​code>​
 +
 +----
 +  * [[rubyinfo|Back to Ruby]]
  
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