I read html page encoded win1251. But I cant render it, because it shows me bad encoded symbols. with utf8 this code works fine. How can I read and show not utf8? Thanks
var charset = require('charset');
var iconv = require('iconv-lite');
var router = express.Router();
// accept POST request on the homepage
router.post('/', function (req, res) {
request(req.body.url, function (error, response, body) {
var result = [];
if (error || response.statusCode != 200) {
console.log(error);
} else {
console.log(charset(response.headers, body));
var enc = charset(response.headers, body);
if (enc != 'utf-8') {
body = iconv.decode(body, 'win1251');
console.log(body);
}
var $ = cheerio.load(body);
//get title
result.push("Title-> " + $("title").text());