[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[Fun With Perl] index.html



I like nifty one liners that justify Perls title as
the "swiss army buzz saw" of computing.

One liners are better than scripts in that you can quickly craft a
one liner to match your exact situation any time something new comes
up...

Suppose you come across a web page with hundreds of pictures or mp3's
that you would like to download. Why tediously go click-click like
a Windows user when you can use Hrvoje Niksic's utility "wget" and perl?

A standard script fails since no two web authors link to their content
in the same manner. A custom crafted one liner works everytime...

First wget the page you want... (wget is avaliable as a debian
GNU/Linux package)

wget http://www.whatever.com/~someone

If you don't have wget, 

perl -MLWP::Simple -e 'mirror( "http://www.whatever.com/~someone",
     "index.html")'

will do the same thing.

This will produce a file "index.html". Inspect index.html to
work out the shape of the links you want to follow then

perl -nle 'print "wget http://www.whatever.com/~someone/$1" 
  if /href="([^"\.]+\.mp3)"/' < index.html | bash -ex

I tried doing this using the LWP::Simple module but it came out about
the same length...
perl -MLWP::Simple -ne 'mirror( "http://www.whatever.com/~someone/$1",$1) 
  if /href="([^\."]+\.mp3)"/' < index.html



John Carter                    EMail: ece@dwaf-hri.pwv.gov.za
Telephone : 27-12-808-0374x194 Fax:- 27-12-808-0338
<http://www.geocities.com/SoHo/Cafe/5947> or <http://iwqs.pwv.gov.za>

Knock. Knock.
Who's there?
GNU.
GNU who?
Don't cry Billy.



==== Want to unsubscribe from this list? (Don't you love us anymore?)
==== Well, if you insist... Send mail with body "unsubscribe" to
==== fwp-request@technofile.org