source: lab.git/misc/nikkei.pl

Last change on this file was 151083b, checked in by mitty <mitty@…>, 11 years ago
  • crawler for Nikkei editorial articles

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@213 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100644
File size: 807 bytes
Line 
1#! /usr/bin/env perl -w
2
3use strict;
4use warnings;
5use utf8;
6
7use LWP::Simple;
8binmode STDOUT => 'encoding(utf8)';
9
10my $directory = shift @ARGV || "./";
11my $nikkei_url = 'http://www.nikkei.com/news/editorial/';
12my $nikkei     = 'http://www.nikkei.com';
13
14my $regex = 'href="([^"]+)(DGXDZO\w+000)/';
15my $javascript = '<script .*?</script>';
16
17my $content = get($nikkei_url);
18while ($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.