mechanize:Mechanize::Page::Label#node
以下のような HTML で
<html> <head> <title>label test</title> </head> <body> <form method="post" action="cgi/test_form00.cgi" name="form1"> <input type="radio" name="radio1" id="r1" value="male" checked="checked"><label for="r1">Male</label> <input type="radio" name="radio1" id="r2" value="female"><label for="r2">Female</label> </form> </body> </html>
>> require 'mechanize' => true >> agent = Mechanize.new => #<Mechanize:0xb74ac538 ... >> page = agent.get('http://127.0.0.1:8080/test05_label.html') => #<Mechanize::Page {url #<URI::HTTP:0xb74a8c1c URL:http://127.0.0.1:8080/test05_label.html>} {meta} {title "label test"} {iframes} {frames} {links} {forms #<Mechanize::Form {name "form1"} {method "POST"} {action "cgi/test_form00.cgi"} {fields} {radiobuttons #<Mechanize::Form::RadioButton:0xb74a0134 @checked=true, @name="radio1", @value="male"> #<Mechanize::Form::RadioButton:0xb749ffcc @checked=false, @name="radio1", @value="female">} {checkboxes} {file_uploads} {buttons}>}> >> page.labels => [#<Mechanize::Page::Label:0xb749a6d0 @page=#<Mechanize::Page {url #<URI::HTTP:0xb74a8c1c URL:http://127.0.0.1:8080/test05_label.html>} {meta} {title "label test"} {iframes} {frames} {links} {forms #<Mechanize::Form {name "form1"} {method "POST"} {action "cgi/test_form00.cgi"} {fields} {radiobuttons #<Mechanize::Form::RadioButton:0xb74a0134 @checked=true, @name="radio1", @value="male"> #<Mechanize::Form::RadioButton:0xb749ffcc @checked=false, @name="radio1", @value="female">} {checkboxes} {file_uploads} {buttons}>}> , @text="Male", @node=#<Nokogiri::XML::Element:0x..fdba4d390 name="label" attributes=[#<Nokogiri::XML::Attr:0x..fdba4b306 name="for" value="r1">] children=[#<Nokogiri::XML::Text:0x..fdba4b0ea "Male">]>>, #<Mechanize::Page::Label:0xb749a658 @page=#<Mechanize::Page {url #<URI::HTTP:0xb74a8c1c URL:http://127.0.0.1:8080/test05_label.html>} {meta} {title "label test"} {iframes} {frames} {links} {forms #<Mechanize::Form {name "form1"} {method "POST"} {action "cgi/test_form00.cgi"} {fields} {radiobuttons #<Mechanize::Form::RadioButton:0xb74a0134 @checked=true, @name="radio1", @value="male"> #<Mechanize::Form::RadioButton:0xb749ffcc @checked=false, @name="radio1", @value="female">} {checkboxes} {file_uploads} {buttons}>}> , @text="Female", @node=#<Nokogiri::XML::Element:0x..fdba4d35e name="label" attributes=[#<Nokogiri::XML::Attr:0x..fdba4909c name="for" value="r2">] children=[#<Nokogiri::XML::Text:0x..fdba48e80 "Female">]>>] >> page.labels[0] => #<Mechanize::Page::Label:0xb749a6d0 @page=#<Mechanize::Page {url #<URI::HTTP:0xb74a8c1c URL:http://127.0.0.1:8080/test05_label.html>} {meta} {title "label test"} {iframes} {frames} {links} {forms #<Mechanize::Form {name "form1"} {method "POST"} {action "cgi/test_form00.cgi"} {fields} {radiobuttons #<Mechanize::Form::RadioButton:0xb74a0134 @checked=true, @name="radio1", @value="male"> #<Mechanize::Form::RadioButton:0xb749ffcc @checked=false, @name="radio1", @value="female">} {checkboxes} {file_uploads} {buttons}>}> , @text="Male", @node=#<Nokogiri::XML::Element:0x..fdba4d390 name="label" attributes=[#<Nokogiri::XML::Attr:0x..fdba4b306 name="for" value="r1">] children=[#<Nokogiri::XML::Text:0x..fdba4b0ea "Male">]>> >> page.labels[0].node => #<Nokogiri::XML::Element:0x..fdba4d390 name="label" attributes=[#<Nokogiri::XML::Attr:0x..fdba4b306 name="for" value="r1">] children=[#<Nokogiri::XML::Text:0x..fdba4b0ea "Male">]>