| 1 | # ABSTRACT: The All Powerful Web Spidering, Scraping, Creeping Crawling Framework | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Dist::Zilla: +PodWeaver | ||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||
| 4 | package Scrappy; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | $Scrappy::VERSION = '0.94112090'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # load OO System | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 10 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # load other libraries | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 10 | extends 'Scrappy::Scraper'; | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub crawl { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
crawl: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my ($self, $starting_url, %pages) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | croak( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self and $starting_url and keys %pages
$self and $starting_url
MC/DC0%0/3
$self and $starting_url and keys %pages
$self
$starting_url
keys %pages
Truth table0%0/4
A and B and C
A= $selfB= $starting_urlC= keys %pages
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 'Please provide a starting URL and a valid configuration before crawling' | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ) unless ($self && $starting_url && keys %pages); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # register the starting url | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | $self->queue->add($starting_url); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # start the crawl loop | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | while (my $url = $self->queue->next) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # check if the url matches against any registered pages | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | foreach my $page (keys %pages) { | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $data = $self->page_match($page, $url); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($data) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # found a page match, fetch and scrape the page for data | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($self->get($url)->page_loaded) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | foreach my $selector (keys(%{$pages{$page}})) { | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # loop through resultset | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | foreach my $item (@{$self->select($selector)->data}) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | # execute selector code | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $pages{$page}->{$selector}->($self, $item, $data); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | __END__ | ||||||||||||||||||||||||||||||||||||||||||