unklejunky has asked for the wisdom of the Perl Monks concerning the following question:
My result is like:#!/usr/bin/perl use strict; use warnings; use utf8; use WWW::Mechanize; use Data::Dumper; use JSON; binmode STDOUT, ':encoding(UTF-8)'; binmode STDIN, ':encoding(UTF-8)'; my $url = 'https://www.autotrader.co.uk/'; my $mech = WWW::Mechanize -> new( autocheck => 1 ); $mech -> agent_alias( 'Linux Mozilla'); if ($mech -> status( $mech -> get($url)) == 200) { $mech -> form_name('searchVehicles'); my @inputs = $mech -> find_all_inputs( name_regex => qr/^(radius|make|mode +l|price-to)$/, type => 'option',); print Dumper \@inputs; };
Note: I have truncated all but the first since you get the idea with the first. The above code returns an array of hashes. I can access all the values that are listed in the Dumper output if I loop over the `@inputs` array and print only the current loop's hash key I want for the corresponding value, but I am after the values of the `<option>` entries. For example, if you inspect the source of the website `searchVehicles` form has an input field for Distance. The drop-down gives you choices between 1 to 200 miles. How do I obtain those values? This is so I can use these values to present and prompt the user of the script with valid options for their search.$VAR1 = [ bless( { 'class' => 'c-form__select', 'current' => 0, 'id' => 'radius', 'menu' => [ { 'name' => 'Distance (national)', 'value' => '', 'seen' => 1 } ], 'type' => 'option', 'aria-label' => 'Choose a distance from your postco +de', 'name' => 'radius', 'idx' => 1 }, 'HTML::Form::ListInput' ), bless( { }, 'HTML::Form::ListInput' ), bless( { }, 'HTML::Form::ListInput' ), bless( { }, 'HTML::Form::ListInput' ) ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I pull HTML form option values?
by marto (Cardinal) on Apr 04, 2018 at 08:09 UTC | |
|
Re: How do I pull HTML form option values?
by NetWallah (Canon) on Apr 03, 2018 at 17:48 UTC | |
by unklejunky (Initiate) on Apr 03, 2018 at 18:56 UTC | |
by NetWallah (Canon) on Apr 04, 2018 at 05:50 UTC | |
by beech (Parson) on Apr 04, 2018 at 21:55 UTC | |
by NetWallah (Canon) on Apr 05, 2018 at 05:49 UTC | |
| |
|
Re: How do I pull HTML form option values?
by bliako (Abbot) on Apr 04, 2018 at 12:20 UTC |