Ross Cameron
2010-Apr-28 07:49 UTC
[Mechanize-users] Adding a missing link to a Mechanize::Page
Some time ago, Jeremy Woertinnk posted a helpful solution to add missing fields to a Mechanize::Form, viz, @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 which worked a treat in fixing forms with badly formed or missing fields. New Problem: how do you add a link to a Mechanize::Page I''ve been researching the documentation(?) and the source code and playing around with it but haven''t been able to crack this one. Can someone please point me in the right direction. Regards Ross -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100428/3a3debf5/attachment-0001.html>
Jeremy Woertink
2010-Apr-29 04:59 UTC
[Mechanize-users] Adding a missing link to a Mechanize::Page
hmm. well, I would create a new Nokogiri::XML::Node of an anchor tag, then create a new Mechanize::Page::Link which takes a node, mech and page then page.links << new_mechanize_link I think that might work for you. ~Jeremy On Wed, Apr 28, 2010 at 12:49 AM, Ross Cameron <ross at roscommonhq.com> wrote:> Some time ago, Jeremy Woertinnk posted a helpful solution to add missing > fields to a Mechanize::Form, viz, > > @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 > > which worked a treat in fixing forms with badly formed or missing fields. > > New Problem: how do you add a link to a Mechanize::Page > > I''ve been researching the documentation(?) and the source code and playing around with it but haven''t been able to crack this one. > > Can someone please point me in the right direction. > > Regards > Ross > > > > > _______________________________________________ > 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/20100428/26e71a5b/attachment.html>
Ross Cameron
2010-Apr-29 05:41 UTC
[Mechanize-users] Adding a missing link to a Mechanize::Page
Jeremy Thanks for that. I had created a Nokogiri::XML::Node OK for the anchor tag intending to add the constructed link as before (page.links << new_mechanize_link) It''s the mech & page parameters of the Mechanize::Page::Link where things got interesting. I couldn''t sort them out. Hoping you can provide some illumination. 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. Jeremy Woertink wrote:> hmm. well, > > I would create a new Nokogiri::XML::Node of an anchor tag, then create > a new Mechanize::Page::Link which takes a node, mech and page then > > page.links << new_mechanize_link > > I think that might work for you. > > ~Jeremy > > On Wed, Apr 28, 2010 at 12:49 AM, Ross Cameron <ross at roscommonhq.com > <mailto:ross at roscommonhq.com>> wrote: > > Some time ago, Jeremy Woertinnk posted a helpful solution to add > missing fields to a Mechanize::Form, viz, > > @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 > > which worked a treat in fixing forms with badly formed or missing fields. > > New Problem: how do you add a link to a Mechanize::Page > > I''ve been researching the documentation(?) and the source code and playing around with it but haven''t been able to crack this one. > > Can someone please point me in the right direction. > > 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 > http://rubyforge.org/mailman/listinfo/mechanize-users-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100429/c5bcafcf/attachment.html>