Created
November 22, 2013 02:55
-
-
Save mussatto/7594012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Time::HiRes; | |
use WWW::Mechanize; | |
use LWP::Simple; | |
my @urls = ("http://www.you24h.com/"); | |
my @errorMessages = ("ERROR", "error"); | |
sub countParams { | |
my $numParameters = @_; | |
print("The number of urls is $numParameters\n"); | |
} | |
sub constainsString{ | |
my $content = $_[0]; | |
my @stringsToBeFound = @{_[1]}; | |
my @stringsFound =(); | |
my $isFound = 0; | |
foreach my $currentString (@stringsToBeFound){ | |
if (index($content, $currentString) != -1) { | |
$isFound = 1; | |
push(@stringsFound, $currentString); | |
} | |
} | |
return ($isFound, @stringsFound); | |
} | |
sub processSubLinks{ | |
my @links = @_; | |
my @filetypesToProcess = ("css", ".jpg", ".jpeg", ".gif", ".png", ".js"); | |
for my $link ( @links ) { | |
my ($isFound) = constainsString($link->url, @filetypesToProcess); | |
if($isFound){ | |
my $linkStart = Time::HiRes::gettimeofday(); | |
print("Getting link:", $link->url, "\n"); | |
get($link->url); | |
my $linkEnd = Time::HiRes::gettimeofday(); | |
print("Time: ", ($linkEnd - $linkStart)*1000," ms\n"); | |
}else{ | |
print ">>>>>>>Skipping :", $link->url, "\n"; | |
} | |
} | |
} | |
sub checkUrls{ | |
my @urls = @{$_[0]}; | |
my @errorMessages = @{$_[1]}; | |
my $retries = $_[2]; | |
print("Number of retries: " . $retries . " \n"); | |
countParams(@urls); | |
for my $url (@urls){ | |
my ($start, $end, $totals); | |
my $count = 0; | |
$totals = 0; | |
for($count; $count <= $retries; $count++) | |
{ | |
my $mech = WWW::Mechanize->new(); | |
$start = Time::HiRes::gettimeofday(); | |
$mech->get($url); | |
my @links = $mech->links(); | |
processSubLinks(@links); | |
$end = Time::HiRes::gettimeofday(); | |
print($url, " testing:\n"); | |
print(($end - $start)*1000," ms\n"); | |
$totals += ($end - $start)*1000; | |
my ($isError, @errorMessagesFound) = constainsString($mech->content, @errorMessages); | |
if($isError){ | |
print("URL ". $url. " contains error messages: ", @errorMessagesFound); | |
} | |
print("****************************** RETRY","\n"); | |
} | |
print ("Average :", ($totals/($retries+1)), "\n"); | |
} | |
} | |
my $retries = 0; | |
checkUrls(\@urls, \@errorMessages, $retries); | |
#testingPassingParameter(\@urls, $retries); | |
#my ($test1, @errors1) = containsErrorMessage("This does not contain flaws."); | |
#my ($test2, @errors2) = containsErrorMessage("This does contain ERROR."); | |
#print(" The Results are :". $test1.", ". $test2. "\n"); | |
#print("The errors1 are: ", @errors1, "\n"); | |
#print("The errors2 are: ", @errors2, "\n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment