Skip to content

Commit

Permalink
tweaked web scraping example a little
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Sep 26, 2012
1 parent 776ef4e commit 93ed965
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -721,8 +721,8 @@ sense for a standalone parser.
say 'Heading: ', shift->all_text;
});

# Recurse through children and extract all text manually
sub all_text {
# Recurse through children manually to extract more than just text
sub text_and_images {
my $elements = shift;
for my $e ($elements->each) {

Expand All @@ -734,13 +734,13 @@ sense for a standalone parser.

# Text from children
my $children = $e->children;
$children->size ? all_text($children) : print $e->text(0);
$children->size ? text_and_images($children) : print $e->text(0);
}

# Text after last element
print $elements->[-1]->text_after(0);
}
all_text($tx->res->dom->children);
text_and_images($tx->res->dom->children);

Especially for unit testing your L<Mojolicious> applications this can be a
very powerful tool.
Expand Down

0 comments on commit 93ed965

Please sign in to comment.