NAME
Scrappy::Scraper::Parser - Scrappy Scraper Data Extrator
VERSION
version 0.92111190
SYNOPSIS
#!/usr/bin/perl
use Scrappy::Scraper::Parser;
my $parser = Scrappy::Scraper::Parser->new;
$parser->html($html);
# get all links in all table rows with CSS selector
my $links = $parser->scrape('table tr a');
# select all links in the 2nd table row of all tables with XPATH selector
my $links = $parser->scrape('//table/tr[2]/a');
# percision scraping !
# select all links in the 2nd table row ONLY with CSS selectors and focus()
my $links =
$parser->select('table tr')
->focus(2)
->scrape('a');
DESCRIPTION
Scrappy::Scraper::Parser provides various tools for scraping/extracting information from web pages using the Scrappy framework.
ATTRIBUTES
The following is a list of object attributes available with every Scrappy::Scraper::Parser instance.
data
The data attribute gets/sets the extracted data which is returned from the scrape method.
my $parser = Scrappy::Scraper::Parser->new;
$parser->select('table tr');
$parser->data;
html
The html attribute gets/sets the HTML content to be parsed and extracted from.
my $parser = Scrappy::Scraper::Parser->new;
$parser->html($HTML);
html_tags
The html_tags attribute gets a hashref of all known HTML tags and attributes to be used with Web::Scraper.
my $parser = Scrappy::Scraper::Parser->new;
$parser->html_tags;
worker
The worker attribute holds the Web::Scraper object which is used to parse HTML and extract data.
my $parser = Scrappy::Scraper::Parser->new;
$parser->worker;
METHODS
focus
The focus method is used zero-in on specific blocks of HTML so the selectors only extract data from within the highlighted block. The focus method is meant to be used after the select method extracts rows of data, the focus method is passed an array index which zeros-in on that row of data.
my $parser = Scrappy::Scraper::Parser->new;
# percision scraping !
# select all links in the 2nd table row ONLY
my $links =
$parser->select('table tr')
->focus(2)
->scrape('a');
scrape
The scrape method is used to extract data from the specified HTML and return the extracted data. This method is dentical to the select method with the exception of what is returned.
my $parser = Scrappy::Scraper::Parser->new;
my $links = $parser->scrape('a', $from_html); #get all links
select
The select method is used to extract data from the specified HTML and return the parser object. The data method can be used to access the extracted information.
my $parser = Scrappy::Scraper::Parser->new;
$parser->select('a', $from_html); #get all links
my $links = $parser->data;
has_html
The has_html method return a boolean which determine whether HTML content has been set.
my $parser = Scrappy::Scraper::Parser->new;
print 'oh no' unless $parser->has_html;
AUTHOR
Al Newkirk <awncorp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by awncorp.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.