NAME

WWW::Mechanize::Query - CSS3 selectors support for WWW::Mechanize.

VERSION

Version 0.01

SYNOPSIS

use WWW::Mechanize::Query;

my $mech = WWW::Mechanize::Query->new( ignore_cache => 0 );
$mech->get( 'http://www.amazon.com/' );
$mech->input( 'input[type="text"][name="field-keywords"]', 'Perl' );
$mech->submit();

print $mech->find('h2.resultCount')->span->text; #prints "Showing 1 - 16 of 7,104 Results"

DESCRIPTION

This module combines WWW::Mechanize with Mojo::DOM making it possible to fill forms and scrape web with help of CSS3 selectors.

For a full list of supported CSS selectors please see Mojo::DOM::CSS.

CONSTRUCTOR

new

Creates a new WWW::Mechanize's new object with any passed arguments.

WWW::Mechanize::Query also adds simple request caching (unless ignore_cache is set to true). Also sets Firefox as the default user-agent (if not explicitly specified).

my $mech = WWW::Mechanize::Query->new( ignore_cache => 0, agent => 'LWP' );

METHODS

Methods provided by WWW::Mechanize can be accessed directly.

Methods provided by Mojo::DOM are accessible by calling dom() method.

dom()

Parses the current content and returns a Mojo::DOM object.

my $dom = $mech->dom;
print $dom->to_xml();

find()

Parses the current content and returns a Mojo::DOM object using CSS3 selectors.

my $mech = WWW::Mechanize::Query->new();
$mech->get( 'http://www.amazon.com/' );
print $mech->find( 'div > h2' )->text;

input()

Gets or sets Form fields using CSS3 selectors.

my $mech = WWW::Mechanize::Query->new();
$mech->get( 'http://www.imdb.com/' );
$mech->input( 'input[name="q"]', 'lost' );    #fill name
$mech->input( 'select[name="s"]', 'ep' );     #select "TV" from drop-down list
$mech->submit();

print $mech->content;
print $mech->input( 'input[name="q"]' );      #prints "lost";

#TODO: Right now it fills out the first matching field but should be restricted to selected form.

SEE ALSO

WWW::Mechanize.

Mojo::DOM

WWW::Mechanize::Cached.

AUTHORS

  • San Kumar (robotreply at gmail)

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by San Kumar.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.