John Rand
John Rand

Reputation: 1034

Why am I getting gibberish content using Perl's WWW::Mechanize?

Perl's WWW::Mechanize returns complete garbage (like ðäD=°"lc*Ñ2\7 õä1û¼Âc{oî´lDNöÓ8ß5o*F2Õ©-õ£z§2ÜÝ1,³íäþwɯÓQÞÆÁS¿IZDKÁ»,ËmÅS1r4!°s,¥4Jl;\J~í2¼) after retrieving a page.

I am sure it is related to the particular web server from which I am trying to download. I need plain html.

Here's the code:

#!/usr/local/bin/perl -w
use WWW::Mechanize;

$url = 'http://www.example.com/brands/';

$mech = WWW::Mechanize->new();
$mech->get($url);
$page = $mech->content();
print "$page\n";

I guess this could be an encoding issue.

Any clues on how to handle this?

Thanks!

Upvotes: 3

Views: 2038

Answers (2)

Marc
Marc

Reputation: 1

I've spent days hunting this down. Mechanize sends a header claiming it does compression, so the server responds with compressed data, which Mechanize doesn't know it has to decode.

The issue manifested itself with error "Status read failed:"

If you force compression by installing and using WWW::Mechanize::GZip, all will work fine.

Upvotes: 0

frezik
frezik

Reputation: 2316

The server may be sending compressed content. Try:

$page = $mech->response->decoded_content;

Upvotes: 5

Related Questions