The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

HTML::Grabber

SYNOPSIS

    use HTML::Grabber;
    use LWP::Simple;

    my $dom = HTML::Grabber->new( html => get('http://twitter.com/ned0r') );

    $dom->find('.tweet-content')->each(sub {
        my $body = $_->find('.tweet-text')->text;
        my $when = $_->find('.js-tweet-timestamp')->attr('data-time');
        my $link = $_->find('.js-permalink')->attr('href');
        print "$body $when (link: $link)\n";
    });

DESCRIPTION

HTML::Grabber provides a jQuery style interface to HTML documents. This makes parsing and manipulating HTML documents trivially simple for those people familiar with http://jquery.com.

It uses XML::LibXML for DOM parsing/manipulation and HTML::Selector::XPath for converting CSS expressions into XPath.

AUTHOR

Martyn Smith <martyn@dollyfish.net.nz>

SELECTORS

All selectors are CSS. They are internally converted to XPath using HTML::Selector::XPath. If some creative selector you're trying isn't working as expected, it may well be worth checking out the documentation for that module to see if it's supported.

METHODS

BUILD

find( $selector )

Get descendants of each element in the current set of matched elements, filtered by a selector.

prev( [ $selector ] )

Get the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector.

next( [ $selector ] )

Get the immediately preceding sibling of each element in the set of matched elements, optionally filtered by a selector.

filter( $selector )

Reduce the set of matched elements to those that match the selector

text_filter( $match )

Filter the current set of matched elements to those that contain the text specified by $match. If you prefer, $match can also be a Regexp

parent()

Get the parent of each element in the current set of matched elements

text()

Get the combined text contents of each element in the set of matched elements, including their descendants.

text_array()

Return text for each element as a list

html()

Return the HTML of the currently matched elements

html_array()

Return the HTML each element as a list

remove()

Removes the matched nodes from the DOM tree returning them

attr( $attribute )

Get the value of an attribute for the first element in the set of matched elements.

each

Execute a sub for each matched node

map

Execute a sub for each matched node returning a list containing the result of each sub

CLASS METHODS

uniq( @nodes )

Internal method for taking a list of XML::LibXML::Elements and returning a unique list