myfrndjk has asked for the wisdom of the Perl Monks concerning the following question:
After processing all url it will display additional"invalid url" string in else loop for example:If i proces totally 5 urls 3-valid and 2-invalid i get 7 results with 2-additional "invalid string"
use LWP::Simple; use File::Compare; use HTML::TreeBuilder::XPath; use LWP::UserAgent; use Win32::Console::ANSI; use Term::ANSIColor; sub crawl_content { { open(FILE, "C:/Users/jeyakuma/Desktop/shipping project/input/input.txt +"); { while(<FILE>) { chomp; $url=$_; foreach ($url) { ($domain) = $url =~ m|www.([A-Z a-z 0-9]+.{3}).|x; } do 'C:/Users/jeyakuma/Desktop/perl/mainsub.pl'; &domain_check(); my $ua = LWP::UserAgent->new( agent => "Mozilla/5.0" ); my $req = HTTP::Request->new( GET => "$url" ); my $res = $ua->request($req); if ( $res->is_success ) { print "working on $domain\n"; binmode ":utf8"; my $xp = HTML::TreeBuilder::XPath->new_from_url($url); my @node = $xp->findnodes_as_string("$xpath") or print + "couldn't find the node\n" ; open HTML, '>:encoding(cp1252)',"C:/Users/jeyakuma/Des +ktop/shipping project/data_$date/$competitor.html"; foreach(<@node>) { print HTML @node; close HTML ; } } else { print color("green"), "$domain Invalid url\n", colo +r("reset") and open HTML,">C:/Users/jeyakuma/Desktop/log.txt"; print + HTML " $domain Invalid URL"; } } } } } do 'C:/Users/jeyakuma/Desktop/perl/comparefinal.pl'; compare_result(); }
output
footwedrer.eu Invalid url
working on autozona.it
dantae.eu Invalid url
working on infanziabimbo.it
working on footlocker.eu
Invalid url
Invalid url
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: if/else loop prints extra values
by kcott (Archbishop) on Jun 28, 2014 at 08:41 UTC | |
by AnomalousMonk (Archbishop) on Jun 28, 2014 at 13:05 UTC | |
by kcott (Archbishop) on Jul 04, 2014 at 18:20 UTC | |
by myfrndjk (Sexton) on Jun 28, 2014 at 09:14 UTC | |
|
Re: if/else loop prints extra values
by Anonymous Monk on Jun 27, 2014 at 14:32 UTC |