Saturday, October 06, 2007

Perl script to automatically dowload files from a web site.

I've been reading Learning Perl book from Randal L. Schwartz and just the introduction gave me the tip to automate a task that otherwise would have taken more time.

Again I am installing Asterisk and a Debian box, I have a list of all the necessary files but now Asterisk put all the sounds files on separate files and not in one package as before.

Instead of downloading 31 pages manually I got a the link to all of them, put them on a file (named filesd) one o each line and run the following Perl script:

open (FILESD, filesd);
while ($pathf = ){
open (WGET, "wget $pathf");
close (WGET);

The filesd file is just a plain file like the one shown below:

ricardo@lmntel01:~/test$ more filesd

I know this could have been done with WGET but I got tired of trying to find the correct flag to download them, and I also know there is no error check, report, fancy things and whistles but hey I just finish the introduction.

No comments: