| RobertS 2005-08-22, 9:56 pm |
| Why doesn't this work? I'm trying to download 50 jpg images returned
with the Yahoo Image Search API using the Yahoo-Search module and store
them to my C:\Perl directory, in 5 groups of 10 results at a time. I'm
using PxPerl 5.8.7 on Windows XP Media Center Edition Service Pack 2,
with version 1.4.7 of the Yahoo-Search module. The modules home page is
at http://search.cpan.org/~jfriedl/Yahoo-Search-1.4.7. If I remove the
"if I < 50" it and the ", AutoContinue=>1", it prints the thumbnail
urls to the urlthumb.txt file like I want and downloads 10 images as I
would expect.
use Yahoo::Search;
use LWP::Simple;
#set count to 50 for maximum speed.
##
## WARNING: DANGEROUS DANGEROUS DANGEROUS
##
if (my $Response = Yahoo::Search->Query(Image => 'Britney', AppId =>
"stalagrs", Count =>10))
{
open(OUT, '>urlthumb.txt') or die "Couldn't open file.";
binmode OUT;
while (my $Result = $Response->NextResult(AutoContinue=>1)) {
printf OUT "%s\n", $Result->ThumbUrl if $Result->I < 15;
#printf "%s\n", $Result->ThumbUrl if $Result->I < 50;
}
{next}
open (OUT, "urlthumb.txt") or die "Couldn't open.";#open for reading
binmode OUT;#in binmode for Windows reading due to \n
@urls = <OUT>;
$url_ref = \@urls;
for ($i = 0; $i <=$#$url_ref; $i++) {
getstore("$url_ref->[$i]", "$i.jpg");
}
}
close(OUT);
|