Debugging WWW::Mechanize scripts – printing requests and responses

Just for fast and easy reference really, but for easy debugging to find out the exact HTTP requests being sent and HTTP responses received by a web-scraping script using the excellent WWW::Mechanize, you can simply add:

$mech->add_handler("request_send", sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });

This will cause all HTTP requests and responses to be output, so you can see exactly what’s happening.

5 thoughts on “Debugging WWW::Mechanize scripts – printing requests and responses”

  1. hi,
    we’ll not get this module when we installed perl(i have installed perl 5.6.1) can u please tell me which version perl have it.

    Thanks & regards

  2. @Deepthi – perl 5.6.1 is ancient (over ten years old) – I’d strongly recommend upgrading to a more recent version (5.10 or above, at least).

    As for WWW::Mechanize, you can install it as you would any other CPAN module (using the cpan client, cpanm (cpanminus), or via your distro’s package tools.

    For example, if you were using Debian, you could use e.g. apt-get install libwww-mechanize-perl.

  3. hi ,
    I have one doubt can we use for configure a file, where file is in html uses css and javascript.I tried but not configured

Comments are closed.