Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

WWW::Mechanize::Firefox, select with multiple names

by gizmo_mathboy (Pilgrim)
on Oct 28, 2011 at 19:43 UTC ( #934489=perlquestion: print w/ replies, xml ) Need Help??
gizmo_mathboy has asked for the wisdom of the Perl Monks concerning the following question:

I'm doing some web scraping and falling short.
#!/usr/local/bin/perl use strict; use warnings; use WWW::Mechanize::Firefox; use 5.010; my $mech = WWW::Mechanize::Firefox->new( autoclose => 0, ); my $url = q(https://selfservice.mypurdue.purdue.edu/prod/bwckctlg.p_disp_dyn_ctl +g?); $mech->get($url); say q(got url); say q(choose term); $mech->form_number(1); $mech->field('cat_term_in', '201220'); $mech->submit(); say q(choose subject); $mech->form_number(1); $mech->select('sel_subj', ['AAE']); $mech->submit(); say $mech->content();
This will generate.
got url choose term choose subject 2 elements found for './/*[(local-name(.)="input" or local-name(.)="se +lect" or local-name(.)="textarea") and @name="sel_subj"]' at ./get_co +urse_descriptions2.pl line 28
I think this is because the html for the page has:
<FORM ACTION="/prod/bwckctlg.p_display_courses" METHOD="POST"> <INPUT TYPE="hidden" NAME="term_in" VALUE="201220"> <INPUT TYPE="hidden" NAME="sel_subj" VALUE="dummy"> ^^^^^ Relavant Hidden Input Type <SNIPPED HTML> vvvvvvvvv Relevant Select Name <SELECT NAME="sel_subj" SIZE="3" MULTIPLE ID="subj_id"> <OPTION VALUE="AAE">AAE-Aero & Astro Engineering
How the do I get it to properly select a value? I think the problem lies in that there is a hidden input type of the same name as the select. The select has a label and id defined but I'm not sure how to use those. I think this script might work in plain WWW::Mechanize but it just returns the same page without giving me this error. Thanks, gizmo

Comment on WWW::Mechanize::Firefox, select with multiple names
Select or Download Code
Re: WWW::Mechanize::Firefox, select with multiple names
by Corion (Pope) on Oct 28, 2011 at 20:02 UTC

    I think you can also pass a DOM object instead of a name, so I'd try:

    my $select = $mech->selector('#sel_subj', single => 1); $mech->select( $select, ['AAE']);

    Update: As noted below, I shouldn't have put the name attribute there but the id attribute.

      While that didn't work. I think the DOM object is subj_id.

      This did work:

      my $select = $mech->selector('#subj_id', single => 1); $mech->select($select, ['AAE']);

      Thanks for the help. I knew there had to be a way to pass the DOM/CSS stuff into it.

      Thanks,

      gizmo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://934489]
Approved by pileofrogs
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2015-07-06 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (71 votes), past polls