Perl Mechanize Returns Jumbled Text

时间:2015-09-01 21:45:01

标签: perl mechanize www-mechanize

I have a form I would like to submit through the Mechanize module.

I have selected the form_number and did a dump_forms() and it returned

POST http://URL (multipart/form-data)
  field1=                (text)
  field2=                (text)
  field3=                (email)
  actionbutton=Enter     (submit)

Here is my resulting code:

#!/usr/bin/perl

use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();

my $url = "http://URL";
$mech->get($url);
$mech->form_number('1');
$mech->dump_forms();
my $result = $mech->submit_form(
    form_number => 1,
    fields       =>
    {
        field1 => 'Test1',
        field2 => 'Test2',
        email => 'test@email.com',
        actionbutton => 'Enter'
    },

);
print $result->content();

But here is what that outputs.

enter image description here

What am I doing incorrectly?

1 个答案:

答案 0 :(得分:3)

You probably want $result->decoded_content(), not $result->content().

See https://metacpan.org/pod/HTTP::Response#r-content-bytes