root/Web-Scraper/trunk/eg/dave-trailer-HD.pl

Revision 2245 (checked in by miyagawa, 14 years ago)

add HD trailer extraction code as an example of callback

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use lib "lib";
6 use Web::Scraper;
7 use URI;
8 use YAML;
9
10 # extract HD trailers from Dave's trailer page
11 my $uri  = URI->new("http://www.drfoster.f2s.com/");
12
13 my $s = scraper {
14     process "td>ul>li", "trailers[]" => scraper {
15         process_first "li>b", title => "TEXT";
16         process_first "ul>li>a[href]", url => '@href';
17         process "ul>li>ul>li>a", "movies[]" => sub {
18             my $elem = shift;
19             return {
20                 text => $elem->as_text,
21                 href => $elem->attr('href'),
22             };
23         };
24     };
25     result "trailers";
26 };
27
28 warn Dump $s->scrape($uri);
Note: See TracBrowser for help on using the browser.