1
我在使用perl中的機械化對使用utf16字符的網站進行機械化調用時出錯。它告訴我這個警告Parsing of undecoded UTF-16 at /usr/local/share/perl5/LWP/UserAgent.pm line 600
我知道這是在我調用$ mech-> content()方法時生成的。有沒有辦法在機械化的內容方法中忽略這些警告?如何在Perl中處理UTF16警告機械化調用
我在使用perl中的機械化對使用utf16字符的網站進行機械化調用時出錯。它告訴我這個警告Parsing of undecoded UTF-16 at /usr/local/share/perl5/LWP/UserAgent.pm line 600
我知道這是在我調用$ mech-> content()方法時生成的。有沒有辦法在機械化的內容方法中忽略這些警告?如何在Perl中處理UTF16警告機械化調用
是的,你可以忽略警告這樣的:
{
no warnings;
#your code that generate false warnings
};
你可以用這個解決編碼錯誤,它可能工作。
WWW :: Mechanize是LWP :: UserAgent的適當子類,您也可以使用LWP :: UserAgent的任何方法。
my $content = $mech->decoded_content();#
if (utf8::is_utf8($content)) {
binmode STDOUT,':utf8';
} else {
binmode STDOUT,':raw';
}
print $content;
第二種方法適用於我。忽略警告會影響我需要警告的其他功能。 – 2013-02-13 09:05:28
這種方式的忽略警告本地化爲閉包。您可以通過這種方式忽略僅一條語句的警告。 – user1126070 2013-02-13 09:43:24
你的意思是「curlies」或「block」。 「關閉」是非常不同的東西。 – ikegami 2013-02-14 06:03:53