Hi, 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?
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? Thanks. #!/usr/bin/perl use strict; use LWP::UserAgent; use HTML::TokeParser; use Data::Dumper; my $url = "http://www.backcountry.com/store/COL0696/Columbia-Camp-Roc-Short-Mens.html"; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.59 Safari/525.19"); # Create a request my $req = HTTP::Request->new(GET => "$url"); $req->content_type('application/x-www-form-urlencoded'); # Pass request to the user agent and get a response back my $res = $ua->request($req); my $content = $res->content(); # Check the outcome of the response if ($res->is_success) { my $stream = HTML::TokeParser->new( \$content ); my $row = 0; while (my $token = $stream->get_token) { # Option Dropdown my $option_count = 0; if (($token->[0] eq 'S') && ($token->[1] eq 'select') && ($token->[2]{'name'} eq 'mv_sku')) { # We're now inside of the Select, we need to keep going to the next until we're out of options, or hit the 'E' /select my @next; push @next, $stream->get_token(); while (($next[0]->[0] ne 'E') && ($next[0]->[1] eq 'select')) { print Dumper($next[0]); print "\n\n"; push @next, $stream->get_token(); exit(); } # end of while on the End Select } print "Options/SKU Count: $option_count\n\n"; $row++; } } exit();