Hello. Sorry for the 2nd email of the day, but I''ve got a select list that is giving me grief, along with the next links, but that was in my first email of the day. =) I have a multi select list and I can''t seem to select the values and submit them. Instead, it looks like they are being ignored. Here''s my code: page = page.form_with(:name => ''search1'') do |search| search.fields.name(''typeSelect'').options[2].select search.checkboxes.name(''checkbox'').check end.submit What am I doing wrong and how can I fix this? THANKS! Cindy -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20081112/ec5559c4/attachment.html>
Hi Cindy! On Wed, Nov 12, 2008 at 11:23:47PM -0600, Cindy Schaller wrote:> Hello. > > > > Sorry for the 2nd email of the day, but I''ve got a select list that is > giving me grief, along with the next links, but that was in my first email > of the day. =)No problem. I try to respond as quickly as possible, but my paying job sometimes gets in the way. ;-)> I have a multi select list and I can''t seem to select the values and submit > them. Instead, it looks like they are being ignored. > > > > Here''s my code: > > > > page = page.form_with(:name => ''search1'') do |search| > > search.fields.name(''typeSelect'').options[2].select > > search.checkboxes.name(''checkbox'').check > > end.submit > > > > > > What am I doing wrong and how can I fix this?Mechanize is probably submitting those fields to the server. Unfortunately the server probably wants other parameters as well that you aren''t setting. Typically what I recommend doing is installing LiveHTTPHeaders * http://livehttpheaders.mozdev.org/ Then submitting the form using Firefox with the livehttpheaders dialog open. That lets you see exactly what Firefox is sending to the server. Step 2, set a logger on your mechanize agent: require ''logger'' require ''mechanize'' agent = WWW::Mechanize.new { |a| a.log = Logger.new(''out.log'') } Then run your script. Mechanize will log what it sends to the server. Compare your Firefox headers to what mechanize sent, then adjust your script until Mechanize sends the same thing that Firefox does. I hope that helps. Unfortunately since I have no context, namely a short failing example, I can''t help you much more than that. -- Aaron Patterson http://tenderlovemaking.com/
Hi Aaron - Sorry, I didn''t mean to say that the response time is slow, I just meant that I was sending multiple emails due to just leaning mechanize. I totally appreciate all of your help. My first email yesterday was about following "Next" links. If anyone has insight on that email, I''d appreciate it. This email was the second issue of the day - select lists. I have the LiveHTTPHeaders installed. Works great. When I added logger to my Mechanize call, it broke the processing. I''ve ran variations of this, but currently I have the following: agent = WWW::Mechanize.new { |a| a.log = Logger.new(''out.log'') } page = page.form_with(:name => ''search1'') do |search| search.fields.name(''selectlist'').options[7].value search.checkboxes.name(''checkbox'').check end.submit The error message is this: c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.0/lib/www/mechanize/chain/respo nse_reader.rb:30:in `handle'': undefined local variable or method `response'' for #<WWW::Mechanize::Chain::ResponseReader:0x3ef2024> (NameError) Any help is appreciated, Cindy -----Original Message----- From: mechanize-users-bounces at rubyforge.org [mailto:mechanize-users-bounces at rubyforge.org] On Behalf Of Aaron Patterson Sent: Wednesday, November 12, 2008 11:34 PM To: Ruby Mechanize Users List Subject: Re: [Mechanize-users] MultiSelect Lists Help Needed Hi Cindy! On Wed, Nov 12, 2008 at 11:23:47PM -0600, Cindy Schaller wrote:> Hello. > > > > Sorry for the 2nd email of the day, but I''ve got a select list that is > giving me grief, along with the next links, but that was in my first email > of the day. =)No problem. I try to respond as quickly as possible, but my paying job sometimes gets in the way. ;-)> I have a multi select list and I can''t seem to select the values andsubmit> them. Instead, it looks like they are being ignored. > > > > Here''s my code: > > > > page = page.form_with(:name => ''search1'') do |search| > > search.fields.name(''typeSelect'').options[2].select > > search.checkboxes.name(''checkbox'').check > > end.submit > > > > > > What am I doing wrong and how can I fix this?Mechanize is probably submitting those fields to the server. Unfortunately the server probably wants other parameters as well that you aren''t setting. Typically what I recommend doing is installing LiveHTTPHeaders * http://livehttpheaders.mozdev.org/ Then submitting the form using Firefox with the livehttpheaders dialog open. That lets you see exactly what Firefox is sending to the server. Step 2, set a logger on your mechanize agent: require ''logger'' require ''mechanize'' agent = WWW::Mechanize.new { |a| a.log = Logger.new(''out.log'') } Then run your script. Mechanize will log what it sends to the server. Compare your Firefox headers to what mechanize sent, then adjust your script until Mechanize sends the same thing that Firefox does. I hope that helps. Unfortunately since I have no context, namely a short failing example, I can''t help you much more than that. -- Aaron Patterson http://tenderlovemaking.com/ _______________________________________________ Mechanize-users mailing list Mechanize-users at rubyforge.org http://rubyforge.org/mailman/listinfo/mechanize-users
[This email is either empty or too large to be displayed at this time]
Sorry, my last email didn''t work. Not sure what happened there. I found the fix to the logger error and was able to generate the output. Here''s the output from LiveHTTPHeaders: GET /?classification=real+estate&temp_type=browse&finder=buy&ad_type=residential -listing%2Cvacation-listing%2Cnew-homes-listing&tp=RE_nj&property=nj.com&fea ture_exists_just_listed=on&feature_includes_property_type=single+family%2Cco ndo HTTP/1.1 My mechanize form submits all of the variables on the form and because I didn''t select options, it gets all of the listings. Net::HTTP::Get: /?classification=real+estate&temp_type=browse&finder=buy&ad_type=residential -listing%2Cvacation-listing%2Cnew-homes-listing&orderby=&advancedMtlSearch=& tp=RE_nj&property=nj.com&neighborhood=&keywords=&feature_includes_condition&feature_includes_property_type=&feature_max_acres=&feature_exists_parking=& feature_exists_garage_type=&ad_no=&zipcode=&map_region=®ion=&adpricemin=& adpricemax=&feature_min_beds=&feature_min_baths=&feature_min_acres=&feature_ min_number_sqfeet=&multiimage=&date_created=&feature_exists_just_listed=on I am going to http://realestate.nj.com The options that I want to submit are just listed, single family and condo. I can''t seem to submit the single family and condo options in the multi select. page = page.form_with(:name => ''search1'') do |search| search.fields.name(''feature_includes_property_typeSelect'').options[0].select #single family search.fields.name(''feature_includes_property_typeSelect'').options[1].select #condo search.checkboxes.name(''feature_exists_just_listed'').check end.submit Any ideas on how to submit this search properly? Thanks, Cindy -----Original Message----- From: mechanize-users-bounces at rubyforge.org [mailto:mechanize-users-bounces at rubyforge.org] On Behalf Of Cindy Schaller Sent: Thursday, November 13, 2008 9:41 AM To: ''Ruby Mechanize Users List'' Subject: Re: [Mechanize-users] MultiSelect Lists Help Needed Hi Aaron - Sorry, I didn''t mean to say that the response time is slow, I just meant that I was sending multiple emails due to just leaning mechanize. I totally appreciate all of your help. My first email yesterday was about following "Next" links. If anyone has insight on that email, I''d appreciate it. This email was the second issue of the day - select lists. I have the LiveHTTPHeaders installed. Works great. When I added logger to my Mechanize call, it broke the processing. I''ve ran variations of this, but currently I have the following: agent = WWW::Mechanize.new { |a| a.log = Logger.new(''out.log'') } page = page.form_with(:name => ''search1'') do |search| search.fields.name(''selectlist'').options[7].value search.checkboxes.name(''checkbox'').check end.submit The error message is this: c:/ruby/lib/ruby/gems/1.8/gems/mechanize-0.8.0/lib/www/mechanize/chain/respo nse_reader.rb:30:in `handle'': undefined local variable or method `response'' for #<WWW::Mechanize::Chain::ResponseReader:0x3ef2024> (NameError) Any help is appreciated, Cindy -----Original Message----- From: mechanize-users-bounces at rubyforge.org [mailto:mechanize-users-bounces at rubyforge.org] On Behalf Of Aaron Patterson Sent: Wednesday, November 12, 2008 11:34 PM To: Ruby Mechanize Users List Subject: Re: [Mechanize-users] MultiSelect Lists Help Needed Hi Cindy! On Wed, Nov 12, 2008 at 11:23:47PM -0600, Cindy Schaller wrote:> Hello. > > > > Sorry for the 2nd email of the day, but I''ve got a select list that is > giving me grief, along with the next links, but that was in my first email > of the day. =)No problem. I try to respond as quickly as possible, but my paying job sometimes gets in the way. ;-)> I have a multi select list and I can''t seem to select the values andsubmit> them. Instead, it looks like they are being ignored. > > > > Here''s my code: > > > > page = page.form_with(:name => ''search1'') do |search| > > search.fields.name(''typeSelect'').options[2].select > > search.checkboxes.name(''checkbox'').check > > end.submit > > > > > > What am I doing wrong and how can I fix this?Mechanize is probably submitting those fields to the server. Unfortunately the server probably wants other parameters as well that you aren''t setting. Typically what I recommend doing is installing LiveHTTPHeaders * http://livehttpheaders.mozdev.org/ Then submitting the form using Firefox with the livehttpheaders dialog open. That lets you see exactly what Firefox is sending to the server. Step 2, set a logger on your mechanize agent: require ''logger'' require ''mechanize'' agent = WWW::Mechanize.new { |a| a.log = Logger.new(''out.log'') } Then run your script. Mechanize will log what it sends to the server. Compare your Firefox headers to what mechanize sent, then adjust your script until Mechanize sends the same thing that Firefox does. I hope that helps. Unfortunately since I have no context, namely a short failing example, I can''t help you much more than that. -- Aaron Patterson http://tenderlovemaking.com/ _______________________________________________ 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