#!/usr/bin/perl -w use LWP::UserAgent; use HTML::TokeParser; use Data::Dumper; my $url = 'http://www.datatool.co.uk/bikes1.asp'; my $url2 = 'http://www.datatool.co.uk/bikes2.asp'; my $browser = LWP::UserAgent->new(); my $response = $browser->get($url); die "Error getting $url: ", $resp->status_line unless $response->is_success; die "It's not HTML, it's ", $resp->content-type unless $response->content_type eq 'text/html'; my $html = $response->content; open(DAT,'>',"c:\\cas.txt") || die("Cannot Open File"); my $stream = HTML::TokeParser->new( \$html ) || die "Couldn't read HTML string: $!"; my @manufact; my @models; while ( my $token = $stream->get_token ) { if ($token->[0] eq 'S' and $token->[1] eq 'option' and $token->[2]{'value'} ne ''){ push(@manufact, $token->[2]{'value'}); } } #print Dumper @manufact; #sleep 5; my $i=0; foreach(@manufact){ $response = $browser->post( $url, [ 'Manufacturer' => "$manufact[$i]", 'btnSearch' => 'Search for matching Models' ] ); die "Error getting $url: ", $resp->status_line unless $response->is_success; die "It's not HTML, it's ", $resp->content-type unless $response->content_type eq 'text/html'; $html = $response->content; # print $html; $stream = HTML::TokeParser->new( \$html ) || die "Couldn't read HTML string: $!"; while ( $token = $stream->get_token ) { if ($token->[0] eq 'S' and $token->[1] eq 'option' and $token->[2]{'value'} ne '' and $token->[2]{'value'} lt 'A') { push(@models, $token->[2]{'value'}); } } my $x=0; while (@models){ $response = $browser->post( $url2, [ 'Manufacturer' => "$manufact[$i]", 'Model' => "$models[$x]", 'btnSearch' => 'Search for matching Models' ] ); die "Error getting $url2: ", $resp->status_line unless $response->is_success; die "It's not HTML, it's ", $resp->content-type unless $response->content_type eq 'text/html'; $x++; $html = $response->content; $stream = HTML::TokeParser->new( \$html ) || die "Couldn't read HTML string: $!"; my $text = $stream->get_text('/table'); print $text; print DAT $text; } } close(DAT);