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