#!/usr/bin/perl -w use strict; use File::Basename; use LWP::Simple; use Getopt::Long; GetOptions( 'wwwroot:s' => (\my $wwwroot), 'staticdir:s' => (\my $outdir), 'server:s' => (\my $server), 'node:i' => (\my @nodes), 'htaccess:s' => (\my $htaccess), 'savepath:s' => (\my $savepath), ); $wwwroot ||= './public_html'; #$htaccess ||= "$wwwroot/.htaccess"; $server ||= "perlmonks.org"; $savepath ||= $wwwroot; my $uri = "http://$server?node_id=%d;style=static"; my $save = "$savepath/%d.html"; # -d $wwwroot or die "wwwroot: '$wwwroot' is no directory."; -d $savepath or die "savepath: '$savepath' is no directory."; if (! scalar @nodes) { open my $hta, "<", $htaccess or die "Couldn't read '$htaccess' : $!"; push @nodes, map { /^\s*RewriteCond %\{QUERY_STRING\} node_id=(\d+)\$/ ? $1 : () } <$hta>; }; for my $node (@nodes) { my $url = sprintf $uri, $node; my $target = sprintf $save, $node; print "Saving $node via $url to $target"; printf ", %d\n", mirror($url, $target); };