in reply to Re: How do I pull HTML form option values?
in thread How do I pull HTML form option values?

Not quite. Here's the form input field for `radius` (Distance):
select class="c-form__select" id="radius" name="radius" aria-label="Ch +oose a distance from your postcode"><option value="">Distance (nation +al)</option><option value="1">Within 1 mile</option><option value="5" +>Within 5 miles</option><option value="10">Within 10 miles</option><o +ption value="15">Within 15 miles</option><option value="20">Within 20 + miles</option><option value="25">Within 25 miles</option><option val +ue="30">Within 30 miles</option><option value="35">Within 35 miles</o +ption><option value="40">Within 40 miles</option><option value="45">W +ithin 45 miles</option><option value="50">Within 50 miles</option><op +tion value="55">Within 55 miles</option><option value="60">Within 60 +miles</option><option value="70">Within 70 miles</option><option valu +e="80">Within 80 miles</option><option value="90">Within 90 miles</op +tion><option value="100">Within 100 miles</option><option value="200" +>Within 200 miles</option></select>

(https://www.autotrader.co.uk/)

I'm after all the values of the `value=` tags for each `<option>`, i.e. 5,10,20,30 etc into an array which I can then use elsewhere in the code. Perhaps find_all_inputs() wasn't the correct way to capture this?

Replies are listed 'Best First'.
Re^3: How do I pull HTML form option values?
by NetWallah (Canon) on Apr 04, 2018 at 05:50 UTC
    From what I can tell, WWW::Mechanize uses HTML::Form, which , in my opinion, does not parse the <select> tag properly.

    The code looks for "multiple":

    if (exists $self->{multiple}) { unshift(@{$self->{menu}}, { value => undef, name => "off"} +); $self->{current} = $checked ? 1 : 0; } else { $self->{current} = 0 if $
    which does not seem to be set anywhere.
    As a result, it only pickes up the first <option>.

    You will likely have to parse the raw html using HTML::TokeParser or the like, to extract the options.

    See fellow un-answered sufferer at stackoverflow.

                    Memory fault   --   brain fried

      From what I can tell, WWW::Mechanize uses HTML::Form, which , in my opinion, does not parse the <select> tag properly. ... excerpt from source code

      Hi,

      I doubt rt://HTML-Form has issue with select tag.

      On the aforementioned website, the distances in miles are provided by javascript.

      HTML::Form, like WWW::Mechanize, doesn't run javascript. For that you'd need WWW::Mechanize::Firefox /..::Chrome/..::PhantomJS

        You are right ! (++)

        The select has an event listener that somehow manages to populate the distance options .. although I could hot figure out how it did that.

        In my debug attempt, I did an "inspect" of the option, and saw the options populated, so I assumed they came from HTML.

        Thanks for identifying the issue!

                        Memory fault   --   brain fried