PreshBlog

Debugging WWW::Mechanize scripts – printing requests and responses

by on Mar.11, 2011, under Perl

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 Comments for this entry

  • Chris

    Thank you for this hint.

  • Deepthi

    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
    Deepthi

  • bigpresh

    @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.

  • deepthi

    Thank you bigpresh

  • deepthi

    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

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!