root/Web-Scraper/trunk/t/05_process_first.t

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.

Line 
1 use strict;
2 use Test::Base;
3
4 use Web::Scraper;
5 plan tests => 1 * blocks;
6
7 filters {
8     selector => 'chomp',
9     expected => 'yaml',
10 };
11
12 run {
13     my $block = shift;
14     my @value;
15     my $s = scraper {
16         process_first $block->selector, sub {
17             my $node = shift;
18             push @value, eval $block->callback;
19             fail $@ if $@;
20         };
21     };
22     $s->scrape($block->html);
23     is_deeply \@value, $block->expected, $block->name;
24 };
25
26 __DATA__
27
28 ===
29 --- html
30 <ul>
31 <li class="foo"><span title="baz">bar1</span></li>
32 <li class="foo"><span title="bad">bar3</span></li>
33 </ul>
34 --- selector
35 li.foo span
36 --- callback
37 $node->attr('title')
38 --- expected
39 - baz
Note: See TracBrowser for help on using the browser.