Node Request with defined charset

HTML view source:

<meta charset="gb2312">



Create a request:
//
request({

        url: url,

        headers: headers,

        encoding: null,

        gzip: true

    }, function callback(error, response, body) {

        if (!error && response.statusCode == 200) {
            
            var iconv = require('iconv-lite');

            // var bodyWithCorrectEncoding = iconv.decode(body, 'iso-8859-1');

            var bodyWithCorrectEncoding = iconv.decode(body, 'gb2312');

            require('fs').writeFileSync('./html.html', bodyWithCorrectEncoding);

        }
}); // ....

Comments