root/Web-Scraper/trunk/eg/hatena-keyword.pl

Revision 2239 (checked in by miyagawa, 13 years ago)

API CHANGE: Now scraper {} returns Web::Scraper object, not the closure.
You should call ->scrape() method to get the data back.

I loved the fact that it returns closure, but technically it doesn't
need to be, and this is actually more compatible with scrapi.rb and
less surprising to people.

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use lib "lib";
5 use URI;
6 use Web::Scraper;
7
8 # same as http://d.hatena.ne.jp/secondlife/20060922/1158923779
9
10 my $keyword = scraper {
11     process 'span.title > a:first-child', title => 'TEXT', url => '@href';
12     process 'span.furigana', furigana => 'TEXT';
13     process 'ul.list-circle > li:first-child > a', category => 'TEXT';
14 };
15
16 my $res = $keyword->scrape(URI->new("http://d.hatena.ne.jp/keyword/%BA%B0%CC%EE%A4%A2%A4%B5%C8%FE"));
17
18 use YAML;
19 warn Dump $res;
20
21 __END__
22 ---
23 category: アイドル
24 furigana: こんのあさみ
25 title: 紺野あさ美
26 url: /keyword/%ba%b0%cc%ee%a4%a2%a4%b5%c8%fe?kid=800
Note: See TracBrowser for help on using the browser.