nodejs encoding using request

后端 未结 3 647
面向向阳花
面向向阳花 2020-12-09 18:40

I am trying to get the correct encoding with request.

request.get({
    \"uri\":\'http://www.bold.dk/tv/\',
    \"encoding\": \"text/html;charset=\'charset=u         


        
3条回答
  •  天涯浪人
    2020-12-09 19:20

    You can use iconv (lite) to convert this. You also need to tell request not to actively set the encoding to the default of UTF-8 by setting the encoding property to null. Therefore you should do:

    var iconv = require('iconv-lite');
    request.get({
        uri:'http://www.bold.dk/tv/',
        encoding: null
      },
      function(err, resp, body){    
        var bodyWithCorrectEncoding = iconv.decode(body, 'iso-8859-1');
        console.log(bodyWithCorrectEncoding);
      }
    );
    

提交回复
热议问题