Perl Tutorials
Using WWW-Mechanize
Perl Basics

Using WWW-Mechanize

Submitting The Form

Once the form has been filled out it's time to submit. The click function operates just like clicking the selected button. Optionally x,y coordinates can be passed. The click_button method can be used to select the button to push based on name, number, value, input. The submit method is used to submit the form without performing a click action. All form submission actions return a HTTP::Response object.


$m->click('button', [x,y]);
$m->click_button(name => 'name');
$m->submit();

Example Scripts

Perform a simple search of google for 'test search'


#!/usr/bin/perl
use WWW::Mechanize;
$url = 'http://www.google.com';
$m->get($url);
$m->form_name('f');
$m->field('q', 'test search');
$response = $m->submit();
print $response->content();

Retrieve www.google.com find the advanced search link. Pull the advanced search page and perform an advanced search using different form field accessors.


#!/usr/bin/perl
use WWW::Mechanize;
$url = 'http://www.google.com';
$m->get($url);
$link = $m->find_link(text => 'Advanced Search');
$m->get($url . $link);
$m->form_name('f');
$m->set_fields('as_q' =? 'test search', 'as_eq' => 'exclude');
$m->select('num', '20');
Manipulating Forms <<  1 2 3
New Content