NAME

HTML::Grabber

SYNOPSIS

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

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

$dom->find('li.status')->each(sub {
    my $body = $_->find('.entry-content')->text;
    my $when = $_->find('.entry-date')->text;
    my $link = $_->find('a[rel="bookmark"]')->attr('href');
    say "$body $when (link: $link)";
});

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.

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.

html()

Return the HTML of the currently matched elements

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

CLASS METHODS

uniq( @nodes )

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