2

I'm making the following request:

var request = require('request');
var cheerio = require('cheerio');

request(url, function(error, response, html) {

  if (!error) {
    var $ = cheerio.load(html);

    console.log(html);
}

And I am only getting jewel characters. How can I get the correct output?

Solution:

I followed the suggestion on this answer.

app.get('/fetchdata', function(req, res) {
  request({
    uri: urlSource,
    //null for encoding to avoid default utf-8
    encoding: null
  }, function(error, response, html) {
    //using iconv to decode to iso-8859 /latin1
      html = iconv.decode(html, 'iso-8859-1');
    console.log(html);
    ...
Community
  • 1
  • 1
  • 1
    do you use utf-8 in all your files? If not, consider it. – Gavriel Jan 19 '16 at 10:48
  • @Gavriel thanks for your answer. I am now considering a middleware like this: `app.use(function(req, res, next) { res.writeHead("Content-Type", "application/json; charset=utf-8"); next(); });` Still no joy, got this error now: Error: Can't set headers after they are sent. – André Varandas Jan 19 '16 at 11:11

0 Answers0