Subject: | Handle multiple process commands within scraper block |
Web::Scraper allows multiple 'process' commands within a scraper block,
e.g.
my $scraper = scraper {
process '//ol/li', 'items[]' => '@id';
process '//div[@id="navigation"]/a[. = "next"]', next => '@href';
};
(which gives { items => [], next => '...' })
It would be nice if WWW::Mechanize::Plugin::Web::Scraper could support this, with something
like the following:
sub scrape {
my ( $mech, @processes ) = @_;
unless ( ref $processes[0] && ref $processes[0] eq 'ARRAY' ) {
@processes = ( [@processes] );
}
my $scraper = scraper { process @{$_} foreach @processes };
return $scraper->scrape( $mech->response );
}
which would allow either the single array (as the current behaviour), or an array of arrayrefs.
For example the above code would become:
$mech->scrape(
[ '//ol/li', 'items[]' => '@id' ],
[ '//div[@id="navigation"]/a[. = "next"]', next => '@href' ],
);
(Thanks for the module anyway - very helpful!)