2009-09-09
■ COMIC ZIN が通販サイトをプレオープンしたのでTOPページの新着ピックアップを取得するWeb::Scraperを手抜きな感じで作った

同人誌だけ取得する仕様。mk_body もうちょっとキレイに書けないものか。
#!/usr/bin/env perl use strict; use warnings; use utf8; use URI; use Web::Scraper 0.22; use YAML; my $url = 'http://shop.comiczin.jp/'; my $s = scraper { process '//a[contains(@class,"title_area") and string-length(@href)=59]', 'entry[]' => +{ title => 'text', link => ['@href', \&as_string], body => ['@href', \&as_string, sub { /=(\d+)$/; $1 }, \&mk_body], }; result qw( entry ); }; $s->user_agent->env_proxy; binmode STDOUT, ":utf8"; print Dump +{ title => 'COMIC ZIN 通信販売', link => $url, entry => $s->scrape(URI->new($url)), }; sub mk_body { my $id = $_; my $dir = int($id / 1000) * 1000; my $c = "http://shop.comiczin.jp/upload/save_image/_$dir/_"; my $m = "${c}m/${id}_"; my $mhtml = qq!<a href="${m}l.jpg"><img src="${m}m.jpg"></a>!; my $s = "${c}s/${id}_s"; my $shtml = join '', map { qq!<a href="$s${_}_l.jpg"><img src="$s${_}_s.jpg"></a>! } qw( 1 2 3 ); "$mhtml$shtml"; } sub as_string { $_->as_string }
Plaggerで使うときはこんな感じのYAML。
plugins: - module: Subscription::Config config: feed: - url: script:/path/to/shop_comiczin_jp.pl - module: CustomFeed::Script
コメント
トラックバック - http://plagger.g.hatena.ne.jp/SweetPotato/20090909
2009-08-22
■ メロンブックス通信販売のWeb::Scraper修正版をCodeReposにコミット

参考にしたのは下記fubaさん版コード。
SweetPotato版のさらなる修正点としては:
- サンプル画像表示はjpgとgifの両方に対応
- サンプル画像表示幅を180pxに固定し、画像から本画像へのリンクを張る
- アイテムのpermalinkを修正し、「/shop/detail/$ID」形式にした
- scraperのXPathを改良し、scraperをひとつだけにした
- カスタマイズ可能な定数を use constant に抜き出した
などなど。
どうぞご利用ください。
URI 1.36 以降を使うとencodeしすぎ問題が起きるようです。下記URLにpatchがあります。
同じものをコピペしておきます。
diff -r 3ba76506db40 -r 1c0cb796154a lib/perl/nolagger/nolagger/lib/Plagger/assets/plugins/CustomFeed-Script/melonbooks.pl --- a/lib/perl/nolagger/nolagger/lib/Plagger/assets/plugins/CustomFeed-Script/melonbooks.pl Sat Aug 22 12:36:42 2009 +0900 +++ b/lib/perl/nolagger/nolagger/lib/Plagger/assets/plugins/CustomFeed-Script/melonbooks.pl Sat Aug 22 12:40:16 2009 +0900 -100,7 +100,7 @@ DA => &MODE, 'ARRIVAL[]' => &ARRIVAL, 'CR[]' => &RATING, - G => encode('utf-8', $genre), + G => $genre, LA => $dt->ymd, SC => $dispstart, P => &ITEMS_PER_PAGE,
トラックバック - http://plagger.g.hatena.ne.jp/SweetPotato/20090822
2009-05-28
■ 今日のコミット

PseudoLink.pm: 追加。リンクのないエントリに疑似的なリンクをセットするFilter。
Changeset 33650 – CodeRepos::Share – Trac
Yahooコミック、ちなこみ、コミックHOLICのWeb::Scraperと、ちなこみのEFTを追加。
Changeset 33651 – CodeRepos::Share – Trac
トラックバック - http://plagger.g.hatena.ne.jp/SweetPotato/20090528
2009-05-23
■ 講談社BOOK倶楽部コミックス発売予定のWeb::ScraperをCodeReposにコミット

サンプルYAML。
plugins: - module: Subscription::Config config: feed: - url: 'script:/path/to/shop_kodansha_jp_bc2_bc_release_schedule_comic.pl' - module: CustomFeed::Script - module: Publish::iCal config: dir: . filename: kodansha.ics
トラックバック - http://plagger.g.hatena.ne.jp/SweetPotato/20090523
2009-03-26
■ expressionハックをEFTより前に行いたい

ある事情でエントリの内容を一旦空にしてからEFTで本文を取得したくなり*1,下記のようなYAMLを書いたら,EFTは成功しているのにエントリ本文は空のままという現象が起こった。
- module: Filter::Rule rule: expression: $args->{entry}->body(undef); 1 - module: Filter::EntryFullText
ざっくり言うと,Filter::Ruleおよびそのruleが実行されるsmartfeed.(entry|feed)フェーズは,EFTが実行されるupdate.entry.fixupフェーズよりも後であるため,このような現象が起こったようだ。
じゃあどうすればいいか。EFTのruleにexpressionハックを記述すればいい。これならEFT本体実行の直前にruleが実行される。
- module: Filter::EntryFullText rule: expression: $args->{entry}->body(undef); 1
*1:念の為:handle_forceで解決できる事情ではない
トラックバック - http://plagger.g.hatena.ne.jp/SweetPotato/20090326