[問題] 抓回來的網頁去除html標籤後出現部份亂碼
寫了一支程式到網路上抓資料,用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
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):
Perl 近期熱門文章
PTT數位生活區 即時熱門文章