Web::Scraper を使う時は YAML::Dump でデバッグすると便利ですね。
別に Web::Scraper を使う時に限らないですね。YAML::Dump は便利ですね。
- scrape_twitter.pl
#!/usr/bin/perl use strict; use warnings; use URI; use Web::Scraper; use Encode; use YAML; my $tweets = scraper { process "li.status", "tweets[]" => scraper { process ".entry-content", body => 'TEXT'; process ".entry-date", when => 'TEXT'; process 'a[rel="bookmark"]', link => '@href'; }; }; my $res = $tweets->scrape( URI->new("http://twitter.com/yoheia") ); print Encode::encode('utf8', YAML::Dump($res));
こんな具合に Dump できます。
$ ./scrape_twitter.pl
---
tweets:
- body: Web::Scraper の filter は便利そう。特定のテキストのみ抽出したい場合とかに。
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10934911386
when: ' 10分前 '
- body: '@otsune さんにコメント頂いた書き方で書きなおしてみた → http://d.hatena.ne.jp/yohei-a/20100319/1269001560'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10934848449
when: ' 12分前 '
- body: '@bambulibro Roger!!'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10933045003
when: ' 約1時間前 '
- body: Job "SYSTEM"."SYS_IMPORT_FULL_02" completed with 3 error(s) at 23:50:01
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10930491273
when: ' 約2時間前 '
- body: 'Import: Release 10.2.0.4.0 - Production on Tuesday, 23 March, 2010 17:52:58'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10930483091
when: ' 約2時間前 '
- body: "@bambulibro I'm going to release 1.3.1... ok?"
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10929373128
when: ' 約2時間前 '
- body: '@bambulibro やっぱりいないじゃないですかーwww'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10929233654
when: ' 約2時間前 '
- body: インデックスは all ok
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10928534141
when: ' 約3時間前 '
- body: function がひとつ無効になっていた。EXECUTE UTL_RECOMP.RECOMP_SERIAL('スキーマ名');で解消した。なんで無効になってたんだろ。
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10928508244
when: ' 約3時間前 '
- body: 2時間40分か、前は2〜3日かかってたからだいぶ速くなった。
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10928268749
when: ' 約3時間前 '
- body: Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" completed with 1 error(s) at 22:21:25
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10928153782
when: ' 約3時間前 '
- body: 'Import: Release 10.2.0.4.0 - 64bit Production on Tuesday, 23 March, 2010 19:42:47'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10928143906
when: ' 約3時間前 '
- body: '@takabow おつかれさまでしたー'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10926496245
when: ' 約3時間前 '
- body: '@takabow 新宿駅で電車待ちしてます'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10926135988
when: ' 約4時間前 '
- body: 'me too RT @takabow: 都営新宿線'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10925832708
when: ' 約4時間前 '
- body: とりあえずラーメン屋に入った。うまい。
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10924702180
when: ' 約4時間前 '
- body: '@bambulibro 戻ったころには一人になりそうw'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10924624034
when: ' 約4時間前 '
- body: 穴場なんですねー @ymotongpoo
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10924515095
when: ' 約4時間前 '
- body: 駒込って田端の近くなのか。知らなかった。
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10923993925
when: ' 約4時間前 '
- body: 'RT @ymotongpoo: 【おしらせ】駒込駅周辺で帰れずに困ってる人は俺の家で遊んだらいいじゃない。'
link: !!perl/scalar:URI::http http://twitter.com/yoheia/status/10923944898
when: ' 約4時間前 '
う〜ん、Web::Scraper すげー。
忘れっぽい自分のための初歩的なメモ。