> Brian Volk wrote: > > Hi All, > > > > I'm having trouble narrow down the correct "<img" tag... > > > > This piece of code will get ALL the "<img" tags: > > > > while (my $img_tag = $parser->get_tag('img')) { > > my $i = $img_tag->[1]; > > my $code = $i->{'src'}; > > print "$code\n" > > } > > > > All I want is the 11th one... so I tried to do a foreach > (1..11) , very > > unsucessful... :~) > > > > Any suggestions would be greatly appreciated.... Here is the whole > > script.... > > > > __begin__ > > > > #!/usr/bin/perl > > > > use strict; > > use warnings; > > use HTML::TokeParser::Simple; > > use LWP::Simple; > > > > my $url = " > > http://www.rcpworksmarter.com/rcp/products/detail.jsp?rcpNum=1013 > > > <http://www.rcpworksmarter.com/rcp/products/detail.jsp?rcpNum=1013> "; > > my $page = get($url) > > or die "Could not load URL\n"; > > > > my $parser = HTML::TokeParser::Simple->new(\$page) > > or die "Could not parse page"; > > > > while (my $img_tag = $parser->get_tag('img')) { > > my $i = $img_tag->[1]; # attributes of this img tag > > my $code = $i->{'src'}; > > print "$code\n"; > > } > > > > __end__ > > > > Thanks! > > > > Brian Volk > > HP Products > > 317.298.9950 x1245 > > <mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED] > > > > > > > > Flemming Greve Skovengaard wrote: > A quick solution could be: > > my $counter = 0; > while (my $img_tag = $parser->get_tag('img')) { > ++$counter; > my $i = $img_tag->[1]; # attributes of this img tag > my $code = $i->{'src'}; > if($counter == 11) { > print "$code\n"; > last; > } > } > > But there is properly a better solution. >
Thank you! Your solution worked great! Brian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>