古詩詞大全網 - 成語用法 - nodejs爬取的數據是unicode怎麽辦

nodejs爬取的數據是unicode怎麽辦

解決辦法為轉成二進制讀取數據 encoding:binary

request({

uri: website_url,

method: 'GET',

encoding: 'binary'

}, function (error, response, body) {

body = new Buffer(body, 'binary');

conv = new iconv.Iconv('WINDOWS-1251', 'utf8');

body = conv.convert(body).toString();

}

});