WWW::Mechanize::DecodedContent - decode Mech content using its HTTP response encoding
use WWW::Mechanize; use WWW::Mechanize::DecodedContent; my $mech = WWW::Mechanize->new; $mech->get($url); my $content = $mech->decoded_content || $mech->content;
WWW::Mechanize::DecodedContent is a plugin to add decoded_content utility method to WWW::Mechanize.
NOTE If you're using WWW::Mechanize 1.50 or later, just use $mech->content and it will return decoded content.
$mech->content
Because it loads HTTP::Response::Encoding module, it automatically adds encoding method to HTTP::Response class.
my $enc = $mech->res->encoding;
Note that $enc might be empty if HTTP response header doesn't contain valid charset attribute.
my $content = $mech->decoded_content;
returns HTML as decoded using HTTP response encoding. Returns undef if encoding is not specified. In that case you might need to get the raw content using $mech->content, and decode it using the default encoding, which is likely to be iso-8859-1.
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTTP::Response::Encoding, WWW::Mechanize
To install WWW::Mechanize::DecodedContent, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mechanize::DecodedContent
CPAN shell
perl -MCPAN -e shell install WWW::Mechanize::DecodedContent
For more information on module installation, please visit the detailed CPAN module installation guide.