作者redmist (....N )
看板Perl
标题[问题] 抓回来的网页去除html标签後出现部份乱码
时间Tue Dec 18 13:13:10 2007
写了一支程式到网路上抓资料,用HTML::FormatText模组去除html标签後会出现部份
乱码(不是全部,甚至只有一小部份),是什麽原因呢?
code如下
use LWP::UserAgent;
use HTML::Parse;
use HTML::FormatText;
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
my $word = '生气';
my $response = $ua->post(
'
http://www.sinica.edu.tw/ftms-bin/scripts/look_for_sym.pl',
[
'kw0' => $word
],
);
if ($response->is_success) {
my $res = $response->content;
#$res =~s/\r\n/\n/;
$ascii = HTML::FormatText->new->format(parse_html($res));
print $ascii;
}
else {
die $response->status_line;
}
印出来的部份结果如下
(1) 书卷气
(2) 书生气
共有2茼P义词
为何会有小部份奇怪的乱码呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.113.241.208