perlutf-16www-mechanize

How to handle UTF16 warning in Perl Mechanize call


I get error while making mechanize call to websites having utf16 characters using mechanize in perl. It shows me this warning Parsing of undecoded UTF-16 at /usr/local/share/perl5/LWP/UserAgent.pm line 600 I know that this is generated when I call $mech->content() method. Is there a way to ignore these warnings in content method of mechanize?


Solution

  • Yes, you could ignore warnings like this:

    {
      no warnings;
      #your code that generate false warnings
    
    };
    

    You could solve the encoding errors with this, it may works.

    WWW::Mechanize is a proper subclass of LWP::UserAgent and you can also use any of LWP::UserAgent's methods.

    my $content = $mech->decoded_content();#
    if (utf8::is_utf8($content)) {
        binmode STDOUT,':utf8';
    } else {
        binmode STDOUT,':raw';
    }
    print $content;