root/Web-Scraper/trunk/t/02_process_multi.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
8 filters {
9     selector => 'chomp',
10     expected => 'yaml',
11 };
12
13 run {
14     my $block = shift;
15     my $s = scraper {
16         process $block->selector, 'text[]' => 'TEXT';
17         result 'text';
18     };
19     my $texts = $s->scrape($block->html);
20     is_deeply $texts, $block->expected, $block->name;
21 };
22
23 __DATA__
24
25 ===
26 --- html
27 <ul>
28 <li class="foo">bar1</li>
29 <li class="bar">bar2</li>
30 <li class="foo">bar3</li>
31 </ul>
32 --- selector
33 li.foo
34 --- expected
35 - bar1
36 - bar3
Note: See TracBrowser for help on using the browser.