Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6928909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:15:02+00:00 2026-05-27T11:15:02+00:00

I use Mechanize to loop through a table, which is paginated. I have a

  • 0

I use Mechanize to loop through a table, which is paginated.

I have a problem with a form that holds multiple submit inputs. The input tags are used as pagination and they are generated dynamically. When I loop through the pages I need to scrape, I need to be able to pick the right input, since only one of them will take me to the “next page”. The right tag can be identified by different attributes such as name, class, value etc. My problem is though, that I can’t find out how to tell mechanize which one to use.

I tried this:

require 'mechanize'
require 'yaml'

url = "http://www.somewhere.com"

agent = Mechanize.new
page = agent.get(url)

loop do

  puts "some content from site using nokogiri"

  if next_page = page.form_with(:action => /.*/)
    page = next_page.submit(page.form_with(:action => /.*/).submits[3])
  else
    break
  end

end

From this post, http://rubyforge.org/pipermail/mechanize-users/2008-November/000314.html, but as told the number of tags are changing so just picking a hardcoded number of the submits is not too good an idea.

What I would like to know is if there is a way like this:

loop do

  puts "some content from site using nokogiri"

  if next_page = page.form_with(:action => /.*/)
    page = next_page.submit(:name => /the_right_submit_button/)
  else
    break
  end

end

or something like that, maybe with a css or xpath selector.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:15:02+00:00Added an answer on May 27, 2026 at 11:15 am

    I usually use form.button_with to select the right button to click:

    form = results_page.forms[0]
    results_page = form.submit(form.button_with(:name=>'ctl00$ContentBody$ResultsPager$NextButton'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two scripts which use Mechanize to fetch a Google index page. I
One can use poll/select when writing a server that can service multiple clients all
I'm trying to use Mechanize to capture a POST request which is not possible
I have a thread that puts data in a buffer and multiple threads that
These are the modules I have installed. use WWW::Mechanize; use XML::Simple; use LWP::Simple; use
In ruby, if you use mechanize following 301/302 redirects like this require 'mechanize' m
I'm trying to use WWW::Mechanize to extract some links from the HTML page using
#!/usr/bin/perl use WWW::Mechanize; use Compress::Zlib; my $mech = WWW::Mechanize->new(); my $username = ; #fill
#!/usr/bin/perl -w use WWW::Mechanize; print $WWW::Mechanize::VERSION.\n; 1) run from Textmate : Can't locate WWW/Mechanize.pm
I'm trying to process Feedback Loop (FBL) messages to unsubscribe people that mark an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.