It works in Firefox, why not in $mech?
Peter Stevens <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.lwp |
|---|---|
| Message-ID | <[email protected]> |
Hi everyone, I have found the attached module to be useful when debugging. In your code, you'll need use WWW::Mechanize::Debug; my $mech = WWW::Mechanize::Debug->new(...) # when you're ready to $mech->click(); print "Request is" . $mech->simulated_click(); Compare this output from what TamperData or LiveHTTPHeaders shows you when submitting the same request, and chances are, you've found your problem :-) Cheers, Peter -- Free Cellphone Monitoring Service www.MinuteWatcher.com
Debug.pm
(text/plain, 1.1 KB)
package WWW::Mechanize::Debug;
# (c) 2006 Peter Stevens. peter (dot) stevens (at) ch-open (dot) ch
# This module may be disutributed under the same conditions as perl itself.
# Debug routine(s?) for use with WWW::Mechanize
#
use strict;
use warnings FATAL => 'all';
our $VERSION = '0.03';
use base qw( WWW::Mechanize );
sub new {
my $class = shift;
my %args = @_;
my $self = $class->SUPER::new( %args );
return $self;
}
sub simulated_click {
# invoke this method where you would invoke $mech->click() to find out what will
# be sent to the server. Compare the results with Firefox/TamperData. If the
# requests are the same, the results should be the same.
#
my $this = shift;
my @args = @_ ;
my ( $f, $r, $t);
$f = $this->current_form(); # or one of its cousins - gives an HTML::Forms object
$r = $f->click( @args ); # gives HTTP::Request object
$r = $this->_modify_request( $r ); # v1.12 internal routine. Compatibility?
$t = $r->as_string(); # text of the request to compare with Tamper Data results.
return $t;
}
return 1;