trunk
Rev | Line | |
---|
[151083b] | 1 | #! /usr/bin/env perl -w |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use utf8; |
---|
| 6 | |
---|
| 7 | use LWP::Simple; |
---|
| 8 | binmode STDOUT => 'encoding(utf8)'; |
---|
| 9 | |
---|
| 10 | my $directory = shift @ARGV || "./"; |
---|
| 11 | my $nikkei_url = 'http://www.nikkei.com/news/editorial/'; |
---|
| 12 | my $nikkei = 'http://www.nikkei.com'; |
---|
| 13 | |
---|
| 14 | my $regex = 'href="([^"]+)(DGXDZO\w+000)/'; |
---|
| 15 | my $javascript = '<script .*?</script>'; |
---|
| 16 | |
---|
| 17 | my $content = get($nikkei_url); |
---|
| 18 | while ($content =~ /$regex/g) { |
---|
| 19 | my $article = "$nikkei$1$2/"; |
---|
| 20 | my $file = "$directory/$2.html"; |
---|
| 21 | |
---|
| 22 | if (-f "$file") { next; } |
---|
| 23 | |
---|
| 24 | system("wget", "-q", $article, '-O', "$file"); |
---|
| 25 | sleep 1; |
---|
| 26 | |
---|
| 27 | if (-f "$file") { |
---|
| 28 | open my $html, "<", $file; |
---|
| 29 | local $/; |
---|
| 30 | my $body = <$html>; |
---|
| 31 | |
---|
| 32 | $body =~ s/$javascript//g; |
---|
| 33 | |
---|
| 34 | open $html, ">", $file; |
---|
| 35 | print $html $body; |
---|
| 36 | } |
---|
| 37 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.