
ragha12
Novice
Sep 12, 2011, 9:19 PM
Post #1 of 2
(1649 views)
|
To stop download when file is already existed in the folder
|
Can't Post
|
|
#!/usr/bin/perl #!/usr/bin/perl use LWP::Simple; use LWP::UserAgent; use HTML::Parse; use HTML::FormatText; use HTML::TreeBuilder::XPath; use NET::SSL; use WWW::Mechanize; use IO::Socket::SSL; use strict; use warnings; my $pageURL; my $simplePage; my @headings; my @array; my $head; my $par; my $var1; my $fileName; my $mech; my $pageContent; $mech = WWW::Mechanize->new; $pageContent = $mech->get("https://some website"); #print $content->content; my $tree = HTML::TreeBuilder::XPath->new; #parsing the URL $tree->parse_content( $pageContent->content ); #print $tree->as_HTML; #Storing into the array and searching @headings = $tree->look_down( id => "resultsetcontainer" ); foreach $head (@headings) { #print "headings -->" . $head->as_XML_indented(). "\n"; #Searching the element in the array @array= $head->find_by_tag_name("a"); foreach $par (@array) { #Storing the each attribute into the variable $var1=$par->attr("href"); #print "$var1\n"; my $var2=substr $var1,21,length($var1); #print "$var2\n"; $fileName = "C:\\outputFiles\\$var2"; my $download =("https://some website"); print "Downloading $download to $fileName \n"; #print "$fileName \n"; $mech->get("$download", ':content_file' => "$fileName" ); if ( $mech->success() ) { print "file downloaded correctly\n"; } else { print "error downloading file:\n"; } } } Hi , This is the code that i have used to download all the files from website, successfully i downloaded all the files. Now when i downloading all the files once again it should not download, it should say that the file is already existed......how to do this...... Anyone tell me please i am waiting for ur reply... Thank you...
|