Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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

by gizmo_mathboy (Friar)
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( +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 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

Replies are listed 'Best First'.
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.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://934489]
Approved by pileofrogs
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2018-04-21 22:11 GMT
Find Nodes?
    Voting Booth?