Bobby wrote:
I'm trying to use LWP to scape a website's content and count the
number of options in a select dropdown box and ran into a bit of a
stubling block.  Below is the code I have so far but it's not getting
the desired results for me, could someone help me look through the
code and give me some suggestions please?

You seem to have made a simple problem a little too complicated. In this case I believe it's better to simply show you a possible solution:

    use LWP::Simple;       # LWP::Simple is sufficient to get a page
    use HTML::TokeParser;

    my $url = 'http://www.backcountry.com/store/COL0696/'
              . 'Columbia-Camp-Roc-Short-Mens.html';
    my $content = get $url;
    my $stream = HTML::TokeParser->new( \$content );

    $stream->get_tag('select');  # 1. get to the first select element
                                 # 2. the get_tag() method seems to be
                                 #    sufficient
    my $count;
    while ( my $token = $stream->get_tag ) {
        $count++ if $token->[0] eq 'option';
        last if $token->[0] eq '/select';
    }
    print "There are $count options.\n";

Please study the above and compare it with your attempt and the HTML::TokeParser docs.

Also, if there are two dropdowns and the second is a dependent of the
first e.g. select size then select availabe colors; how do i count
the total possible combinations of those two options?

Sounds like simple math to me.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to