WWW::Mechanize tutorial

Posted on 2011-09-11
Last Modified: 2012-05-12
I am new to pearl and I would like to learn about WWW::Mechanize,
can someone share me some good links or books with many examples?

Note: I didn't find many examples on
Question by:pravink22
  • 5
  • 2
LVL 23

Expert Comment

ID: 36519420
There are several examples here:

I've written many scripts using WWW::Mechanize - I'll go through them and find a few examples that I can share and post them here.
LVL 23

Accepted Solution

nemws1 earned 125 total points
ID: 36519451
I use the Mac Dashboard applet from Junecloud called 'Delivery Status' to track shipments, but I'm often not at a Mac when I get the e-mail, so I whipped up this script using WWW::Mechanize to add a package to my tracking list.

Usage: --from DeliveryCompany --item "Cool New Thing" --no 123456789012345

The most important thing is usually to create the HTTP::Cookies object, as many websites use cookies for tracking.

Author Comment

ID: 36556565
Urs doc is not accessible, can you reattach once again?
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

LVL 23

Expert Comment

ID: 36556636
Sure thing. ;-)

Author Comment

ID: 36556652
When I tried to download, I am getting the following error msg:

You don't have permission to access /incoming/2011/09_w39/ on this server.

Can you copy paste it?
LVL 23

Expert Comment

ID: 36556654
Hmmm... that still comes up as forbidden.  Let me just paste it.
# Track a package using Junecloud
# File:
# Author: Nem W Schlecht
#   Copyright © 2009
#   License: Creative Commons Attribution-Share Alike
# Creation Date: Apr 06, 2009

use WWW::Mechanize;
use HTTP::Cookies;
use Getopt::Long;

my $from;
my $name;
my $track;

my $res = GetOptions("from=s" => \$from,
                     "item=s" => \$name,
                     "no=s" => \$track);

if (length($from) < 2 || length($name) < 2 || length($track) < 2) {
    print "Usage: $0 --from <shipco> -item <itemname> -no <tracknum>\n";
    print "\tShipping companies:\n";
    while (<DATA>) {
        next unless /\.com$/;
        print "\t$_\n";

my $url = "";
my $m = new WWW::Mechanize;


                form_number => '1',
                fields => {
                    email => '',
                    password => 'S3cr3tPaSsw0rD',
                    remember => '30'

my $from_host;
while (<DATA>) {
    next unless /\.com$/;
    if (/$from/) {
        $from_host = $_;

                form_number => '1',
                fields => {
                    cmd => 'add',
                    type => 'web',
                    from => $from_host,
                    name => $name,
                    no => $track

<option value="">Adobe (US and Canada)</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""> (coming soon)</option>
<option value="">Apple - by email address</option>
<option value="">Apple - by zip code</option>
<option value="">Apple - Japan, by email address</option>
<option value="">Apple - Japan, by zip code</option>
<option value="">Apple - Hong Kong</option>
<option value="">Aramex</option>
<option value="">Canada Post</option>
<option value="">City Link</option>
<option value="">DHL - Express</option>
<option value="">DHL - GlobalMail</option>
<option value="">DHL - Germany</option>
<option value="">DPD - Germany</option>
<option value="">FedEx</option>
<option value="">GLS</option>
<option value="">Google Checkout</option>
<option value="">Hermes Logistik Gruppe - Germany</option>
<option value="">Hongkong Post</option>
<option value="">Japan Post - EMS</option>
<option value="">Japan Post - Morning 10 Overnight Mail</option>
<option value="">Japan Post - Registered Mail</option>
<option value="">Japan Post - Yu-Pack</option>
<option value="">La Poste (coming soon)</option>
<option value="">OnTrac</option>
<option value="">Parcelforce</option>
<option value="">Post Danmark</option>
<option value="">Poste Italiane - Postacelere1 Plus</option>
<option value="">Poste Italiane - Paccocelere1 Plus</option>
<option value="">Poste Italiane - Paccocelere Maxi</option>
<option value="">Poste Italiane - Paccocelere3</option>
<option value="">Poste Italiane - Paccocelere Internationale</option>
<option value="">Poste Italiane - EMS</option>
<option value="">Posten - Norway</option>
<option value="">Posten - Sweden</option>
<option value="">Purolator</option>
<option value="">Royal Mail</option>
<option value="">Sagawa Express</option>
<option value="">Swiss Post</option>
<option value="">TNT - by consignment number</option>
<option value="">TNT - by reference number</option>
<option value="">TNT Post - Netherlands</option>
<option value="">UPS</option>
<option value="">UPS Mail Innovations</option>
<option value="">US Postal Service</option>
<option value="">Yamato Transport</option>
<option value="other">Other</option>

Open in new window

LVL 23

Expert Comment

ID: 36556661
To use WWW::Mechanize there are 2 things you should know/do.  First, if you have Firefox with the Web Developer plugin, you can easily trace out FORM names and elements, which you'll need to submit specific forms.  The other thing is to just use trial and error.  I'll often call "print $m->content();" at various stages to make sure I'm getting the desired results.

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can Oracle Client work with an Oracle 12c Database? 5 165
Replace  text in a file 2 114
.properties file to call function/method 9 61
Perl string filter 5 82
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question