1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#!/usr/bin/env perl
use strict;
use warnings;
use 5.020;
use Mojo::UserAgent;
use Mojo::URL;
use Path::Tiny qw( path );
my $root = Mojo::URL->new('http://localhost:8080');
my $ua = Mojo::UserAgent->new;
sub fetch
{
my $path = shift || '/';
my $url = $root->clone;
$url->path($path);
say "GET $url";
my $result = $ua->get($url)->result;
$result->code == 200 or die "@{[ $result->code ]} @{[ $result->message ]}";
return $result;
}
my $index_html = fetch();
foreach my $a ($index_html->dom->find('a')->each)
{
my $name = $a->attr('href');
my $doc = fetch("/$name/");
my $output = path(__FILE__)->absolute->parent->parent->parent->child("corpus/apache-$name.html");
say "WRITE file://localhost$output";
$output->spew_utf8($doc->body);
}
|