1

I cannot display chinese character response to browser using nodejs ?

jsdom.env({ html: 'http://www.baidu.com',
    scripts: ['http://code.jquery.com/jquery-1.6.min.js']
}, function (err, window) {
    //Use jQuery just as in a regular HTML page
    var $ = window.jQuery;

    res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
    res.end($('title').text());
});

Incorrect result : �ٶ�һ�£�����֪��

Correct result should be : 百度一下,你就知道

user717166
  • 690
  • 2
  • 10
  • 17

1 Answers1

1

因为百度的网页编码是GBK的

because the charset of baidu.com is GBK

tuoxie007
  • 1,234
  • 12
  • 10