Answer the question
In order to leave comments, you need to log in
How to convert from windows-1251 to utf-8?
I'm trying to parse from a site that has an encoding:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
var request = require('request');
var cheerio = require('cheerio');
var Buffer = require('buffer').Buffer;
var Iconv = require('iconv').Iconv;
var iconv = new Iconv('CP1251','UTF-8');
request(url, function(error, response, body){
var $ = cheerio.load(body);
var str = $('#selector').text();
console.log(iconv.convert(str).toString()); // кракозябры: пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ
});
Answer the question
In order to leave comments, you need to log in
Try
installing like this: npm install iconv-lite
iconv = require('iconv-lite');
result = iconv.encode(iconv.decode(new Buffer(body, 'binary'), 'win1251'), 'utf8'));
I haven't checked it myself yet, it wasn't before.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question