root/Web-Scraper/trunk/eg/twitter-friends.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 my $nick = shift || "miyagawa";
9 my $uri  = URI->new("http://twitter.com/$nick");
10
11 my $twitter = scraper {
12     process 'a[rel="contact"]',
13         'friends[]' => scraper {
14             process 'a',   url => '@href', name => '@title';
15             process 'img', src => '@src';
16         };
17     result 'friends';
18 };
19
20 my $friends = $twitter->scrape($uri);
21
22 use YAML;
23 warn Dump $friends;
24
Note: See TracBrowser for help on using the browser.