Hi, I''ve recently had some trouble setting form values in my code - for example: require ''rubygems'' require ''mechanize'' def save(pagename, content, editsummary = '''') agent = WWW::Mechanize.new agent.user_agent = ''Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'' page = agent.get(''http://en.wikipedia.org/w/index.php?title='' + pagename + ''&action=edit'') form = page.forms.with.name("editform").first form.wpTextbox1 = content form.wpSummary = editsummary page = agent.submit form end save(''User:Tim.bounceback/testing'', ''bleh'') Yields the following error message: bleh.rb:8:in `save'': undefined method `wpTextbox1='' for nil:NilClass (NoMethodError) from bleh.rb:12 Any help would be appreciated Thanks! Tim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/mechanize-users/attachments/20070512/83f4907c/attachment.html
On Sat, May 12, 2007 at 01:27:11PM -0400, Timothy van Bremen wrote:> Hi, > > I''ve recently had some trouble setting form values in my code - for example: > > require ''rubygems'' > require ''mechanize'' > def save(pagename, content, editsummary = '''') > agent = WWW::Mechanize.new > agent.user_agent = ''Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'' > page = agent.get(''http://en.wikipedia.org/w/index.php?title='' + pagename > + ''&action=edit'') > form = page.forms.with.name("editform").first > form.wpTextbox1 = content > form.wpSummary = editsummary > page = agent.submit form > end > save(''User:Tim.bounceback/testing'', ''bleh'') > > Yields the following error message: > bleh.rb:8:in `save'': undefined method `wpTextbox1='' for nil:NilClass > (NoMethodError) > from bleh.rb:12 > Any help would be appreciatedThere doesn''t seem to be any form with the name ''editform''. I verified that in my browser and with mechanize. -- Aaron Patterson http://tenderlovemaking.com/
OK, but what''s this? <form id="editform" name="editform" method="post" action="/w/index.php?title=%27User:Tim.bounceback/testing%27&action=submit" enctype="multipart/form-data"> It can be found on line 126 (for me). Tim -- Tim: "So would that be a paradox?" Andy: "No, that would just create a hole in the space-time continuum."
On Sun, May 13, 2007 at 09:06:50AM -0400, Timothy van Bremen wrote:> OK, but what''s this? > > <form id="editform" name="editform" method="post" > action="/w/index.php?title=%27User:Tim.bounceback/testing%27&action=submit" > enctype="multipart/form-data"> > > It can be found on line 126 (for me).Are you logged in to wikipedia in your browser? I think you have to be logged in to get that form. If thats the case, you''d have to get mechanize to log in to wikipedia before it could see that form. -- Aaron Patterson http://tenderlovemaking.com/