homepage Welcome to WebmasterWorld Guest from 54.235.16.159
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Building array of options?
WWW::Mechanize and <select><option>
jshanley




msg:3726497
 5:55 pm on Aug 19, 2008 (gmt 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>
<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]

 

phranque




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

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:
[search.cpan.org...]

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...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved