source: lab/trunk/misc/nikkei.pl @ 213

Last change on this file since 213 was 213, checked in by mitty, 11 years ago
  • crawler for Nikkei editorial articles
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.