How to handle UTF16 warning in Perl Mechanize call

南笙酒味 提交于 2019-12-24 07:09:37

问题


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?


回答1:


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;



回答2:


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;

please explain where it use


来源:https://stackoverflow.com/questions/14847893/how-to-handle-utf16-warning-in-perl-mechanize-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!