Fork me on GitHub

2008/12/05

Recent entries from same category

  1. perldocのbash-completionが激しく便利でうれしょん出た。 Hatena
  2. Perl音痴な私がPerlを使っている理由 Hatena
  3. TatsumakiとDUI Streamを使って画像ストリーミングサーバ作ってみた。 Hatena
  4. のび太の物は俺の物。俺の物は俺の物。 Hatena
  5. Plackで高速サーバがWindowsでも動くようにした Hatena

はてな
久々Plaggerネタ。めんどくさいので説明なしで...
スクリプト
hatena-news.pl
use strict;
use warnings;
use utf8;
use Web::Scraper;
use URI;

my $uri = URI->new( "http://news.hatelabo.jp/" );
my $entry_scanner = scraper {
    process 'h1.article', summary => 'TEXT';
    process 'div.section', body => 'RAW';
};

my $scanner = scraper {
    process '//td[.//span[text()="主なニュース"]]//ul/li',
        'entries[]' => scraper {
            process 'a',
                title => 'TEXT',
                link => '@href',
                info => sub {
                  $entry_scanner->scrape(
                      URI->new_abs( $_->attr('href'), $uri )
                  );
                }
        };
   result 'entries';
};

my $feed = {
    title => 'はてなニュース',
    link  => $uri->as_string,
};

for my $entry (@{ $scanner->scrape( $uri ) }) {
    push @{$feed->{entries}}, {
        title   => $entry->{title},
        link    => $entry->{link},
        summary => $entry->{info}->{summary},
        body    => $entry->{info}->{body},
    };
}

use YAML;
binmode STDOUT, ":utf8";
print Dump $feed;

hatena-news.yaml
global:
  log:
    level: error
plugins:
  - module: Subscription::Config
    config:
      feed:
        - script:///path/to/hatena-news.pl
  - module: CustomFeed::Script
  - module: Publish::Feed
    config:
      dir: /path/to/hatena-news
      filename: hatena-news.rss
      format: RSS
※Windowsで動かす人は環境変数PATHEXTを以下の様にしておく必要あり
set PATHEXT=%PATHEXT%;.PL

あと、出力先はご自由にPublish::なんちゃらで...
ま、その内フィード出来るだろけど。
Posted at 17:15 in ソフトウェア::lang::perl | WriteBacks (1) | Edit
Tagged as: plagger
Bookmarks: このエントリーのtweets add to hatena add to hatena | add to delicious.com | add to livedoor.clip add to livedoor.clip | add to buzzurl add to buzzurl | add to fc2bookmark add to fc2bookmark | add to Yahoo Bookmark add to Yahoo Bookmark | add to Pookmark add to Pookmark

blog comments powered by Disqus
WriteBacks

Plagger CustomFeed::Script mixiニュースのRSSを生成

Plaggerを使って、mixiニュース一覧から本文を抜き出しフィードを生成するplagger::CustomFeed::Scriptです。

Posted by WEBデザイン BLOG at 2009/01/21 (Wed) 05:16:25

TrackBack ping me at
Post a comment

writeback message: Ready to post a comment.