Ross Cameron
2010-Jan-08 05:17 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Hi This may be a dumb question with an obvious answer. It would seem that an input form field identified with an ''id'' qualifier and not with a ''name'' qualifier is not recognised by Mechanize - at least it isn''t in the form field list. Is there any way of getting at these elements or am I, as I suspect, fresh out of luck. But you never know ... Appreciate any help. Regards Ross -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100108/22249069/attachment.html>
jeremywoertink at gmail.com
2010-Jan-08 05:52 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Did you try grabbing it by the id with nokogiri? On Jan 7, 2010, at 9:17 PM, Ross Cameron <ross at roscommonhq.com> wrote:> Hi > > This may be a dumb question with an obvious answer. > > It would seem that an input form field identified with an ''id'' > qualifier and not with a ''name'' qualifier is not recognised by > Mechanize - at least it isn''t in the form field list. > > Is there any way of getting at these elements or am I, as I suspect, > fresh out of luck. But you never know ... > > Appreciate any help. > > Regards > Ross > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users
Ross Cameron
2010-Jan-08 10:42 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Yes, it can be grabbed by Nokogiri. But, not sure how it helps because I want to stuff the field value and submit the form. Not too familiar with Nokogiri to say it can''t do it and having been through the classes docs, I can''t see how it could. After all, it''s simply a parser is it not. Or am I not correct? Always willing to learn. Would appreciate any assistance here. Regards Ross. ------------------------------------------------------------------------ Ross Cameron | Director Roscommon Pty Ltd | ABN 85 099 499 840 p: +61 2 9016 4133 <callto:+61%202%209016%204133> | m: +61 4 3312 9087 <callto:+61%204%203312%209087> | f: +61 2 9420 4525 <callto:+61%202%209420%204525> | w: www.roscommonhq.com <http://www.roscommonhq.com> | AIM: rossppc Roscommon uses the five sentences <http://five.sentenc.es> email reply policy. Please consider our environment before printing this email. NOTE: This email and any attachments may be confidential. If received in error, please delete the email. Because emails and attachments may be interfered with, may contain computer viruses or other defects and may not be successfully replicated on other systems, you must be cautious. Roscommon cannot guarantee that what you receive is what we sent. If you have any doubts about the authenticity of an email from Roscommon, please contact us immediately. jeremywoertink at gmail.com wrote:> Did you try grabbing it by the id with nokogiri? > > > > On Jan 7, 2010, at 9:17 PM, Ross Cameron <ross at roscommonhq.com> wrote: > >> Hi >> >> This may be a dumb question with an obvious answer. >> >> It would seem that an input form field identified with an ''id'' >> qualifier and not with a ''name'' qualifier is not recognised by >> Mechanize - at least it isn''t in the form field list. >> >> Is there any way of getting at these elements or am I, as I suspect, >> fresh out of luck. But you never know ... >> >> Appreciate any help. >> >> Regards >> Ross >> >> _______________________________________________ >> Mechanize-users mailing list >> Mechanize-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mechanize-users > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100108/e66aeb37/attachment.html>
jeremywoertink at gmail.com
2010-Jan-08 17:09 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
You could try page.search("#someid").attr("value","somevalue") Then try submitting. That would be awesome if it worked! Let me know :) On Jan 8, 2010, at 2:42 AM, Ross Cameron <ross at roscommonhq.com> wrote:> Yes, it can be grabbed by Nokogiri. But, not sure how it helps > because I want to stuff the field value and submit the form. Not too > familiar with Nokogiri to say it can''t do it and having been through > the classes docs, I can''t see how it could. After all, it''s simply a > parser is it not. Or am I not correct? > > Always willing to learn. > > Would appreciate any assistance here. > > Regards > Ross. > Ross Cameron | Director > Roscommon Pty Ltd | ABN 85 099 499 840 > p: +61 2 9016 4133 | m: +61 4 3312 9087 | f: +61 2 9420 4525 | w: www.roscommonhq.com > | AIM: rossppc > > Roscommon uses the five sentences email reply policy. Please > consider our environment before printing this email. > > NOTE: This email and any attachments may be confidential. If > received in error, please delete the email. Because emails and > attachments may be interfered with, may contain computer viruses or > other defects and may not be successfully replicated on other > systems, you must be cautious. Roscommon cannot guarantee that what > you receive is what we sent. If you have any doubts about the > authenticity of an email from Roscommon, please contact us > immediately. > > > jeremywoertink at gmail.com wrote: >> >> Did you try grabbing it by the id with nokogiri? >> >> >> >> On Jan 7, 2010, at 9:17 PM, Ross Cameron <ross at roscommonhq.com> >> wrote: >> >>> Hi >>> >>> This may be a dumb question with an obvious answer. >>> >>> It would seem that an input form field identified with an ''id'' >>> qualifier and not with a ''name'' qualifier is not recognised by >>> Mechanize - at least it isn''t in the form field list. >>> >>> Is there any way of getting at these elements or am I, as I >>> suspect, fresh out of luck. But you never know ... >>> >>> Appreciate any help. >>> >>> Regards >>> Ross >>> >>> _______________________________________________ >>> Mechanize-users mailing list >>> Mechanize-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/mechanize-users >> _______________________________________________ >> Mechanize-users mailing list >> Mechanize-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mechanize-users > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100108/b28d02b4/attachment.html>
Ross Cameron
2010-Jan-09 03:23 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Jeremy As you say, that would be awesome, but unfortunately it doesn''t work as we might''ve hoped. Stuffing the attributes works as expected. Submitting the form does not, however. Any thoughts? Ross jeremywoertink at gmail.com wrote: You could try page.search("#someid").attr("value","somevalue") Then try submitting. That would be awesome if it worked! Let me know :) Ross Cameron wrote:> Yes, it can be grabbed by Nokogiri. But, not sure how it helps because > I want to stuff the field value and submit the form. Not too familiar > with Nokogiri to say it can''t do it and having been through the > classes docs, I can''t see how it could. After all, it''s simply a > parser is it not. Or am I not correct? > > Always willing to learn. > > Would appreciate any assistance here. > > Regards > Ross. > > jeremywoertink at gmail.com wrote: >> Did you try grabbing it by the id with nokogiri? >> >> >> >> On Jan 7, 2010, at 9:17 PM, Ross Cameron <ross at roscommonhq.com> wrote: >> >>> Hi >>> >>> This may be a dumb question with an obvious answer. >>> >>> It would seem that an input form field identified with an ''id'' >>> qualifier and not with a ''name'' qualifier is not recognised by >>> Mechanize - at least it isn''t in the form field list. >>> >>> Is there any way of getting at these elements or am I, as I suspect, >>> fresh out of luck. But you never know ... >>> >>> Appreciate any help. >>> >>> Regards >>> Ross >>> >>> _______________________________________________ >>> Mechanize-users mailing list >>> Mechanize-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/mechanize-users >> _______________________________________________ >> Mechanize-users mailing list >> Mechanize-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mechanize-users > ------------------------------------------------------------------------ > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100109/be23f8cf/attachment.html>
jeremywoertink at gmail.com
2010-Jan-09 07:14 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Hmm... I''m not in front of my machine to try, but.. In mechanize can you use << with the fields? If so... Try input = page.search("#someid") input.attr("name", "somename") page.forms.first.fields << input maybe that will put it in there for you. Hope that works! On Jan 8, 2010, at 7:23 PM, Ross Cameron <ross at roscommonhq.com> wrote:> Jeremy > > As you say, that would be awesome, but unfortunately it doesn''t work > as we might''ve hoped. > > Stuffing the attributes works as expected. Submitting the form does > not, however. > > Any thoughts? > > Ross > > jeremywoertink at gmail.com wrote: > > You could try > > page.search("#someid").attr("value","somevalue") > > Then try submitting. That would be awesome if it worked! Let me > know :) > Ross Cameron wrote: >> >> Yes, it can be grabbed by Nokogiri. But, not sure how it helps >> because I want to stuff the field value and submit the form. Not >> too familiar with Nokogiri to say it can''t do it and having been >> through the classes docs, I can''t see how it could. After all, it''s >> simply a parser is it not. Or am I not correct? >> >> Always willing to learn. >> >> Would appreciate any assistance here. >> >> Regards >> Ross. >> >> jeremywoertink at gmail.com wrote: >>> >>> Did you try grabbing it by the id with nokogiri? >>> >>> >>> >>> On Jan 7, 2010, at 9:17 PM, Ross Cameron <ross at roscommonhq.com> >>> wrote: >>> >>>> Hi >>>> >>>> This may be a dumb question with an obvious answer. >>>> >>>> It would seem that an input form field identified with an ''id'' >>>> qualifier and not with a ''name'' qualifier is not recognised by >>>> Mechanize - at least it isn''t in the form field list. >>>> >>>> Is there any way of getting at these elements or am I, as I >>>> suspect, fresh out of luck. But you never know ... >>>> >>>> Appreciate any help. >>>> >>>> Regards >>>> Ross >>>> >>>> _______________________________________________ >>>> Mechanize-users mailing list >>>> Mechanize-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/mechanize-users >>> _______________________________________________ >>> Mechanize-users mailing list >>> Mechanize-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/mechanize-users >> >> _______________________________________________ >> Mechanize-users mailing list >> Mechanize-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/mechanize-users > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100108/86cbf2cf/attachment-0001.html>
Ross Cameron
2010-Jan-09 11:32 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Jeremy Again, another little feature I''ve learnt - thanks. Following your suggestion, the form looks like this: page.forms.first.fields << input.shift # input was an Array - see your code below #<WWW::Mechanize::Form {name "form1"} {method "GET"} {action "form2.php"} {fields #<WWW::Mechanize::Form::Field:0xb708fcfc @name="debug", @value="1"> #<WWW::Mechanize::Form::Field:0xb708fb30 @name="html", @value="1"> #(Element:0x..fdb848784 { name = "input", attributes = [ #(Attr:0x..fdb842532 { name = "type", value = "text" }), #(Attr:0x..fdb842528 { name = "id", value = "url" }), #(Attr:0x..fdb84251e { name = "size", value = "60" }), #(Attr:0x..fdb842514 { name = "maxlength", value = "1024" }), #(Attr:0x..fdb84250a { name = "*value*", value = "*abcdef*" })] })} {radiobuttons} ... which is derived from the following test case html <form method="get" action="form2.php" target="_blank"> <p> <input type="hidden" name="debug" value="1" /> <input type="hidden" name="html" value="1" /> URL: <input type="text"* id="url"* size="60" maxlength="1024" value="" /> </p> <p class="c"> ... where the field id = ''url'' was stuffed with ''abcde'', which, on submit, returns the run time error: ...gems/mechanize-0.9.3/lib/www/mechanize/form.rb:142:in `proc_query'': undefined method `query_value'' for #<Nokogiri::XML::Element:0xb7065074> (NoMethodError) The field was added to the form as above. I am guessing there might a way to cast the Nokogiri or Element class to WWW::Mechanize, in which case it could be a solution??? Ross jeremywoertink at gmail.com wrote:> Hmm... I''m not in front of my machine to try, but.. > In mechanize can you use << with the fields? If so... > Try > input = page.search("#someid") > input.attr("name", "somename") > page.forms.first.fields << input > > maybe that will put it in there for you. > > Hope that works! > > > > On Jan 8, 2010, at 7:23 PM, Ross Cameron <ross at roscommonhq.com > <mailto:ross at roscommonhq.com>> wrote: > >> Jeremy >> >> As you say, that would be awesome, but unfortunately it doesn''t work as we might''ve hoped. >> >> Stuffing the attributes works as expected. Submitting the form does not, however. >> >> Any thoughts? >> >> Ross >> >> jeremywoertink at gmail.com <mailto:jeremywoertink at gmail.com> wrote: >> >> You could try >> >> page.search("#someid").attr("value","somevalue") >> >> Then try submitting. That would be awesome if it worked! Let me know :) >> >> Ross Cameron wrote: >>> Yes, it can be grabbed by Nokogiri. But, not sure how it helps >>> because I want to stuff the field value and submit the form. Not too >>> familiar with Nokogiri to say it can''t do it and having been through >>> the classes docs, I can''t see how it could. After all, it''s simply a >>> parser is it not. Or am I not correct? >>> >>> Always willing to learn. >>> >>> Would appreciate any assistance here. >>> >>> Regards >>> Ross. >>> >>> jeremywoertink at gmail.com <mailto:jeremywoertink at gmail.com> wrote: >>>> Did you try grabbing it by the id with nokogiri? >>>> >>>> >>>> >>>> On Jan 7, 2010, at 9:17 PM, Ross Cameron <ross at roscommonhq.com >>>> <mailto:ross at roscommonhq.com>> wrote: >>>> >>>>> Hi >>>>> >>>>> This may be a dumb question with an obvious answer. >>>>> >>>>> It would seem that an input form field identified with an ''id'' >>>>> qualifier and not with a ''name'' qualifier is not recognised by >>>>> Mechanize - at least it isn''t in the form field list. >>>>> >>>>> Is there any way of getting at these elements or am I, as I >>>>> suspect, fresh out of luck. But you never know ... >>>>> >>>>> Appreciate any help. >>>>> >>>>> Regards >>>>> Ross >>>>> >>>>> _______________________________________________ >>>>> Mechanize-users mailing list >>>>> Mechanize-users at rubyforge.org <mailto:Mechanize-users at rubyforge.org> >>>>> http://rubyforge.org/mailman/listinfo/mechanize-users >>>> _______________________________________________ >>>> Mechanize-users mailing list >>>> Mechanize-users at rubyforge.org <mailto:Mechanize-users at rubyforge.org> >>>> http://rubyforge.org/mailman/listinfo/mechanize-users >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> Mechanize-users mailing list >>> Mechanize-users at rubyforge.org <mailto:Mechanize-users at rubyforge.org> >>> http://rubyforge.org/mailman/listinfo/mechanize-users >> _______________________________________________ >> Mechanize-users mailing list >> Mechanize-users at rubyforge.org <mailto:Mechanize-users at rubyforge.org> >> http://rubyforge.org/mailman/listinfo/mechanize-users > ------------------------------------------------------------------------ > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100109/953e93ce/attachment.html>
Jeremy Woertink
2010-Jan-10 04:26 UTC
[Mechanize-users] input form fields not in the #<WWW::Mechanize::Form array
Hey Ross, Did you ever get it? Sorry, I was at CES all day :) It was awesome. Anyway, if you''re pushing the information into this field, and it has no name, then just make a new one with the correct name and value :) @new_field = WWW::Mechanize::Form::Field.new("url", " http://www.justprofessionals.com") # shameless plug :) page.forms.first.fields << @new_field @new_page = page.forms.first.submit See if that works for ya, and let me know :) ~Jeremy On Sat, Jan 9, 2010 at 3:32 AM, Ross Cameron <ross at roscommonhq.com> wrote:> Jeremy > > Again, another little feature I''ve learnt - thanks. > > Following your suggestion, the form looks like this: > > page.forms.first.fields << input.shift # input was an Array - see > your code below > > #<WWW::Mechanize::Form > {name "form1"} > {method "GET"} > {action "form2.php"} > {fields > #<WWW::Mechanize::Form::Field:0xb708fcfc @name="debug", @value="1"> > #<WWW::Mechanize::Form::Field:0xb708fb30 @name="html", @value="1"> > #(Element:0x..fdb848784 { > name = "input", > attributes = [ > #(Attr:0x..fdb842532 { name = "type", value = "text" }), > #(Attr:0x..fdb842528 { name = "id", value = "url" }), > #(Attr:0x..fdb84251e { name = "size", value = "60" }), > #(Attr:0x..fdb842514 { name = "maxlength", value = "1024" }), > #(Attr:0x..fdb84250a { name = "*value*", value = "*abcdef*" })] > })} > {radiobuttons} ... > > > which is derived from the following test case html > > <form method="get" action="form2.php" target="_blank"> > <p> > <input type="hidden" name="debug" value="1" /> > <input type="hidden" name="html" value="1" /> > URL: <input type="text"* id="url"* size="60" maxlength="1024" > value="" /> > </p> > <p class="c"> ... > > where the field id = ''url'' was stuffed with ''abcde'', > > which, on submit, returns the run time error: > ...gems/mechanize-0.9.3/lib/www/mechanize/form.rb:142:in `proc_query'': > undefined method `query_value'' for #<Nokogiri::XML::Element:0xb7065074> > (NoMethodError) > > The field was added to the form as above. I am guessing there might a way > to cast the Nokogiri or Element class to WWW::Mechanize, in which case it > could be a solution??? > > > Ross > > > jeremywoertink at gmail.com wrote: > > Hmm... I''m not in front of my machine to try, but.. > In mechanize can you use << with the fields? If so... > Try > input = page.search("#someid") > input.attr("name", "somename") > page.forms.first.fields << input > > maybe that will put it in there for you. > > Hope that works! > > > > On Jan 8, 2010, at 7:23 PM, Ross Cameron <ross at roscommonhq.com> wrote: > > Jeremy > > As you say, that would be awesome, but unfortunately it doesn''t work as we might''ve hoped. > > Stuffing the attributes works as expected. Submitting the form does not, however. > > Any thoughts? > > Ross > jeremywoertink at gmail.com wrote: > > You could try > > page.search("#someid").attr("value","somevalue") > > Then try submitting. That would be awesome if it worked! Let me know :) > > > Ross Cameron wrote: > > Yes, it can be grabbed by Nokogiri. But, not sure how it helps because I > want to stuff the field value and submit the form. Not too familiar with > Nokogiri to say it can''t do it and having been through the classes docs, I > can''t see how it could. After all, it''s simply a parser is it not. Or am I > not correct? > > Always willing to learn. > > Would appreciate any assistance here. > > Regards > Ross. > > jeremywoertink at gmail.com wrote: > > Did you try grabbing it by the id with nokogiri? > > > > On Jan 7, 2010, at 9:17 PM, Ross Cameron < <ross at roscommonhq.com> > ross at roscommonhq.com> wrote: > > Hi > > This may be a dumb question with an obvious answer. > > It would seem that an input form field identified with an ''id'' qualifier > and not with a ''name'' qualifier is not recognised by Mechanize - at least it > isn''t in the form field list. > > Is there any way of getting at these elements or am I, as I suspect, fresh > out of luck. But you never know ... > > Appreciate any help. > > Regards > Ross > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > > ------------------------------ > > _______________________________________________ > Mechanize-users mailing listMechanize-users at rubyforge.orghttp://rubyforge.org/mailman/listinfo/mechanize-users > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users > > ------------------------------ > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.orghttp://rubyforge.org/mailman/listinfo/mechanize-users > > > _______________________________________________ > Mechanize-users mailing list > Mechanize-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/mechanize-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100109/e586cf0a/attachment-0001.html>