Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Check website has update file using www::mechanize

by perlmad (Sexton)
on May 25, 2016 at 05:50 UTC ( [id://1164033]=perlquestion: print w/replies, xml ) Need Help??

perlmad has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I am using www::mechanize module to download a set of zip files from webpage and I have a small problem that's I need to download only updated file only

Any Idea

  • Comment on Check website has update file using www::mechanize

Replies are listed 'Best First'.
Re: Check website has update file using www::mechanize
by GrandFather (Saint) on May 25, 2016 at 06:06 UTC

    Show us what you tried and tell us how it failed.

    Premature optimization is the root of all job security

      I have tried this

      # subroutine for file downloading and moves to corresponding location sub file_download { my @temp_download_file_names=@{$_[0]}; my @temp_download_url=@{$_[1]}; my $dir_path=$_[2]; my $dir_name=$_[3]; print "\n\n Please Wait file is Downloading \n\n"; for(my $ii=0;$ii<=$#temp_download_file_names;$ii++){ $mech->get($home_url.$temp_download_url[$ii]); $http_response=$mech->res(); if($http_response->is_success){ $filename=$http_response->filename(); } else { $filename="untitled"; } $mech->save_content($filename); system "mv ./$filename $dir_path$dir_name/"; print " File name",$filename," is Downloaded \ +n\n"; $mech->back(); } } }

      How Can i check the download file is updated or already downloaded???

        The following may help:

        #!/usr/bin/perl use warnings; use strict; use WWW::Mechanize; my $url = 'http://perlmonks.org/?'; my $mech = WWW::Mechanize->new(); my $response = $mech->head($url); my $modDate = $response->header('last-modified'); if (defined $modDate) { print "Modification date: $modDate\n"; } else { print "Last modification date not available\n"; }

        Prints:

        Modification date: Wed, 25 May 2016 07:45:13 GMT
        Premature optimization is the root of all job security
Re: Check website has update file using www::mechanize
by Anonymous Monk on May 25, 2016 at 06:34 UTC

      Is this Possible with Http::Response ???

      If yes, then how can get the last modified information from http response ???

        HTTP has provisions for not sending data if it is younger than a given timestamp. See the ->mirror method of LWP::UserAgent and/or the If-Modified-Since header of HTTP.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1164033]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-18 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found