root/Web-Scraper/trunk/t/01_process.t

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

if expression starts with /, it's treated as direct XPath expression, not CSS selector.

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 => 'chomp',
10 };
11
12 run {
13     my $block = shift;
14     my $s = scraper {
15         process $block->selector, text => 'TEXT';
16         result 'text';
17     };
18     my $text = $s->scrape($block->html);
19     is $text, $block->expected, $block->name;
20 };
21
22 __DATA__
23
24 ===
25 --- html
26 <div id="foo">bar</div>
27 --- selector
28 div#foo
29 --- expected
30 bar
31
32 ===
33 --- html
34 <span><a href="foo">baz</a></span>
35 --- selector
36 span a[href]
37 --- expected
38 baz
39
40 ===
41 --- html
42 <span><a href="foo">baz</a></span>
43 --- selector
44 //span/a
45 --- expected
46 baz
Note: See TracBrowser for help on using the browser.