mechanize:Mechanize::Form::SelectList#options_with
以下のような HTML で
<html> <head> <title>form test</title> </head> <body> <form method="get" action="cgi/foo00.cgi" name="form1"> <select name="select1"> <option>1</option> <option>2</option> </select> <select name="select2" multiple> <option>foo</option> <option>bar</option> </select> </form> </body> </html>
>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb7405594 ... >> page = agent.get('http://127.0.0.1:8080/test20_select.html') => #<Mechanize::Page ... >> f = page.form('form1') => #<Mechanize::Form ... >> f.fields[0].options => [#<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[...], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="1", @value="1">, #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[...], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="2", @value="2">] >> f.fields[0].options_with(:value => //).each {|x| p x} #<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[#<Mechanize::Form::Option:0xb73f7cc8 ...>, #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 ...>, @selected=false, @text="2", @value="2">], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="1", @value="1"> #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[#<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 ...>, @selected=false, @text="1", @value="1">, #<Mechanize::Form::Option:0xb73f7c14 ...>], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="2", @value="2"> => [#<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[#<Mechanize::Form::Option:0xb73f7cc8 ...>, #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 ...>, @selected=false, @text="2", @value="2">], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="1", @value="1">, #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[#<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 ...>, @selected=false, @text="1", @value="1">, #<Mechanize::Form::Option:0xb73f7c14 ...>], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="2", @value="2">] >> f.fields[0].options_with(:value => //).each {|x| p x.value} "1" "2" => [#<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[#<Mechanize::Form::Option:0xb73f7cc8 ...>, #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 ...>, @selected=false, @text="2", @value="2">], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="1", @value="1">, #<Mechanize::Form::Option:0xb73f7c14 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 @options=[#<Mechanize::Form::Option:0xb73f7cc8 @select_list=#<Mechanize::Form::SelectList:0xb73f8448 ...>, @selected=false, @text="1", @value="1">, #<Mechanize::Form::Option:0xb73f7c14 ...>], @name="select1", @value=[], @node=#<Nokogiri::XML::Element:0x..fdb9fc260 name="select" attributes=[#<Nokogiri::XML::Attr:0x..fdb9faa32 name="name" value="select1">] children=[#<Nokogiri::XML::Element:0x..fdb9fbe82 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9cea "1">]>, #<Nokogiri::XML::Element:0x..fdb9fbe78 name="option" children=[#<Nokogiri::XML::Text:0x..fdb9f9524 "2">]>]>>, @selected=false, @text="2", @value="2">]