#!/usr/bin/perl use strict; use warnings; use Web::Scraper; use URI; use utf8; use HTTP::Date; use XML::TreePP; use XML::FeedPP; # URL my $uri = 'アドレス'; # RSS作成 my $feed = XML::FeedPP::RSS->new(); my $now = time(); # RSSの内容 $feed->title( "タイトル" ); $feed->description( "概要" ); $feed->link( $uri ); $feed->pubDate( $now ); # スクレイピング設定 my $scraper = scraper { # process : 全部取得 # process_first : 最初の一つ process 'CSSセレクタまたはXPATH', 'list[]' => { link => '@href', title => 'TEXT' }; result "list"; }; # スクレイピングのデータ取得 my $res = $scraper->scrape(URI->new($uri)); for (my $i = 0; $i < $#{$res->{title}}; $i++) { # 記事取得 my $content = scraper { process_first 'CSSセレクタまたはXPATH', 'str' => 'TEXT'; result 'str'; }; my $description = $content->scrape($res->[$i]{link}); # RSSにスクレイピングした情報のアイテム追加 $feed->add_item(link => $res->[$i]{link}->as_string, title => $res->[$i]{title}, description => $description ); } # ファイルに保存 $feed->to_file( "xxxxx.rss" ); # フィルタ用のRSS情報 my $feeds = XML::FeedPP::RSS->new(); $feeds->title( "タイトル" ); $feeds->description( "概要" ); $feeds->link( $uri ); $feeds->pubDate( $now ); # フィルタリング my @items = $feed->match_item( description => qr/フィルタ/ ); # タイトル title => # リンク link => # 概要 description => # マッチしたアイテムをRSSに追加 foreach my $item ( @items ) { $feeds->add_item($item); } # ファイルに保存 $feeds->to_file( "yyyyy.rss" ); # ブラウザに出力 print "Content-Type: text/xml; charset=UTF-8\n\n"; print $feeds->to_string( "UTF-8" );
kimonoからの移植は
kimonoの「Data Model View」の「Advanced」のセレクタをコピー
my $uri = 'アドレス'; my $scraper = scraper { process 'CSSセレクタ コピー1', 'data1[]' => 'TEXT'; process 'CSSセレクタ コピー2', 'data2[]' => 'TEXT'; };
データー取得できるのであとはRSS等に変換すればいい。
imabari.hateblo.jp
imabari.hateblo.jp
imabari.hateblo.jp
imabari.hateblo.jp