2011年10月11日

WWW::MechanizeがContent-Typeを無視している?

$mech->content()
$mech->save_content('file.html')


出力がブラウザで正しく表示されない?
コンテンツ内の'Content-Type'にかかわらず、「utf8」で出力している気がする。


ヘッダより、エンコード文字を取得する方法。
その他、いろいろ試すも、効果がありません。。。。

my $res=$mech->get('http://kakaku.com');
my $ct = $res->headers->header('Content-Type');
$mech->delete_header('Content-Type');
$mech->add_header('Content-Type'=>'text/html; charset=Shift_JIS');
$mech->content()
$mech->save_content('file.html')


さぁ~、どうしよう、、、、
><)/~



Posted by kanedayo at 01:57│Comments(2)
この記事へのコメント
ひとまず、わかったこと。

use HTTP::Response::Encoding とすると、

$res->charset や
$res->encoding が利用できて、

my $enc = $res->encoding;
open(my $fh, ">:encoding($enc)", 'file.html');
print {$fh} $mech->content;
close($fh);

みたいなことすると、適切な文字コードで保存してくれる。
Posted by kanedayokanedayo at 2011年10月12日 00:57
http://code.google.com/p/www-mechanize/issues/detail?id=221

投稿してみました。
バグなら直してくれるだろうし、
使い方が間違っていたら、指摘していただけるかなぁ~と思い。^^;
Posted by kanedayokanedayo at 2011年10月15日 02:03
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。