So, this module uses HTML::Selector::XPath and only supports the CSS 3 selector supported by that module. Web::Query doesn't support jQuery's extended queries(yet?). If a selector is passed as a scalar ref, it'll be taken as a straight XPath expression.

FUNCTIONS

wq($stuff)

This is a shortcut for Web::Query->new($stuff). This function is exported by default.

METHODS

CONSTRUCTORS

my $q = Web::Query->new($stuff, \%options )

Create new instance of Web::Query. You can make the instance from URL(http, https, file scheme), HTML in string, URL in string, URI object, undef, and either one HTML::Element object or an array ref of them.

This method returns undefined value on non-successful response with URL.

Currently, the only two valid options are indent, which will be used as the indentation string if the object is printed, and no_space_compacting, which will prevent the compaction of whitespace characters in text blocks.

The value passed for an attribute can be a code ref. In that case, the code will be called with $_ set to the current attribute value. If the code modifies $_, the attribute will be updated with the new value.

$q->attr( alt => sub { $_ ||= 'A picture' } );

id

Get/set the elements's id attribute.

In getter mode, it behaves just like attr().

In setter mode, it behaves like attr(), but with the following exceptions.

If the attribute value is a scalar, it'll be only assigned to the first element of the set (as ids are supposed to be unique), and the returned object will only contain that first element.

my $first_element = $q->id('the_one');

It's possible to set the ids of all the elements by passing a sub to id(). The sub is given the same arguments as for each(), and its return value is taken to be the new id of the elements.

html

insert_before

Insert every element in the set of matched elements before the target.

insert_after

Insert every element in the set of matched elements after the target.

prepend

Insert content, specified by the parameter, to the beginning of each element in the set of matched elements.

remove

Delete the elements associated with the object from the DOM.

# remove all <blink> tags from the document
$q->find('blink')->remove;

remove_class

Remove a single class, multiple classes, or all classes from each element in the set of matched elements.

replace_with

Replace the elements of the object with the provided replacement. The replacement can be a string, a Web::Query object or an anonymous function. The anonymous function is passed the index of the current node and the node itself (with is also localized as $_).

How to find XML processing instructions in a document?

However, note that the support for processing instructions in HTML::TreeBuilder::LibXML::Node is sketchy, so there are methods like attr() that won't work.

Can't get the content of script elements

The <script> tag is treated differently by HTML::TreeBuilder, the parser used by Web::Query. To retrieve the content, you can use either the method html() (with the caveat that the content will be escaped), or use Web::Query::LibXML, which parse the 'script' element differently.

As a valued partner and proud supporter of MetaCPAN, StickerYou is
happy to offer a 10% discount on all Custom Stickers,
Business Labels, Roll Labels,
Vinyl Lettering or Custom Decals. StickerYou.com
is your one-stop shop to make your business stick.
Use code METACPAN10 at checkout to apply your discount.