use strict; use warnings; use WWW::Mechanize::Firefox; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $input = "file.txt"; open (my $FI, "<", $input) or die "Unable to open $input: $!\n"; #The following will eventually be reworked as hash my @kbnums; my @schools; for <$FI> { m/(KB\d*)\s(.*)/i; push(@kbnums, $1); push(@schools, $2); } my $url = 'https://start.of.url/'; my $mech = WWW::Mechanize::Firefox->new(); my $zip = Archive::Zip->new(); #$checkLoad was added to verify the file write was complete my $checkLoad = "some text that appears at bottom of page"; my $count = 0; for (@kbnums) { my $file = "$schools[$count].html"; my $addr = "$url$_"; my $attempts = 0; do { $mech->get($addr, synchronize=> 0, ':content_file' => $file); $attempts++; }while (!(grep($checkLoad, $file)) && ($attempts < 10) ); #Added this to verify the $file has the $checkLoad written grep($checkLoad, $file) ? print "$file - SUCCESS" : print "$file - FAIL"; $zip->addFile($file); $count++; } my $status = $zip->overwriteAs('EOC-triage.zip'); die "Unable to write Zip - $status : $!\n" if $status != AZ_OK;