Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Building array of options?

WWW::Mechanize and <select><option>

5:55 pm on Aug 19, 2008 (gmt 0)

New User

5+ Year Member

joined:Aug 19, 2008
posts: 1
votes: 0

Hi all,

I'd love to be able to build an array based on the available <option> choices for a form. WWW::Mechanize seems like a logical choice, but I'm not sure how to scrape out the data I need.

The goal: To walk the number of pages shown, emulating a user choosing "next page". Setting the page # is easy in WWW::Mechanize, but I dont know how to scrape the total number of pages, so we don't try to open additional pages that don't exist. The number of pages is dynamic, and changes every few hours.

The relevant snippet of code follows:

# --- start html
<td align="center" width="20%">Page:
<select name="selPage" id="selPage" onchange="document.frmTickTop.submit();">
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option></select>

<td align="center" width="60%">

# --- end html

Dumping the form in WWW::Mechanize shows:

hidSortBy=TICKET.ID DESC (hidden readonly)
selPage=1 (option) [*1񔘝񔿷񕧑񖎫1011121314151617181920...830831832833834835836837838839840841]
selStatus=ALL (option) [*ALL/AllPEN/OpenOLD/HoldLOSED/Closed]
selPerPage=10 (option) [*102550100]

However, I don't know how to build an array of page numbers. I would appreciate any help. Thanks!

[edited by: phranque at 8:52 am (utc) on Aug. 20, 2008]
[edit reason] fix sidescroll [/edit]

9:25 am on Aug 20, 2008 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 106

welcome to WebmasterWorld [webmasterworld.com], jshanley!

i'm not sure i understand exactly what you are trying to build.
are you saying you have a page containing one or more forms and you want to get all the options for a named select input parameter?

you can get a list of forms using WWW::Mechanize which returns HTML::Form objects and you can use HTML::Form methods to get option values:

something like this:
use HTML::Form;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get( $url );
my @forms = $mech->forms();
foreach my $form (@forms) {
my $input = $form->find_input('selPage');
@possible_values = $input->possible_values;
# do something with your list of values
last if $input;

or if you are trying to find the page stack to create a SelPage select for the current page history, you might try doing something with the internal functions $mech->_push_page_stack() / $mech->_pop_page_stack() but you're on your own there...


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members