Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

silent11 (2860)

silent11
  (email not shown publicly)
http://silent11.com/

Journal of silent11 (2860)

Monday August 30, 2004
08:53 AM

BOM.pl

[ #20633 ]

#!/usr/bin/perl

use strict;
use LWP::Simple;
use HTML::TokeParser;

# usage Links("URL","File Extension","Save Files to");
# This will download the Book of Mormon in MP3 format.

Links("http://lds.org/mp3/display/0,18692,5297-41,00.html", "mp3" , "./BofM/");

sub Links
    {
        my $count = 0;
        my $url   = shift;
        my $type  = shift;
        my $dir   = shift;

            if ( defined $dir )
                {
                    # mkdir $dir || die $!;
                    print "$dir directory was created\n";
                }

        print "URL : $url \n TYPE: $type \n\n";

        unless ( defined $url )
            {
                return("No URL Provided\n");
                die $!;
            }
        unless ( defined $type )
            {
                return("No Link Type Provided\n");
                die $!;
            }

        my $html = get( $url );

        my $page = HTML::TokeParser->new(\$html);

        while ( my $token = $page->get_tag("a"))
            {
                 my $url = $token->[1]{href} || "-";
                 my $file = $url;
                    $file =~ s/^.+\///;

             if ($url =~ /$type$/i)
              {
              print "Getting $url as $file \n\n";
              sleep 3;
              getstore( $url , $dir . '/' . $file ) || die $!;
              $count ++;
            }
            }
        }

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.