Converting from Windows-1255 to UTF-8 in Node JS

不问归期 提交于 2019-12-11 10:27:11

问题


I'm extracting text from a Windows-1255-encoded webpage using Node.js. I'm trying to decode the text using the windows-1255.

After installing it using NPM and requiring it in the relevant file, I tried using it like this:

var title = windows1255.decode('#title').text());

This doesn't seem to have any effect. Any idea why?

Thanks!

Morgan


回答1:


don't know if you still waiting for an answer about this issue, but the following worked for me...

When fetching the data (a file), I set the get options of encoding to be binary:

var options = {
        method: 'GET',
        url: 'myURL',
        encoding: 'binary' 
    };

    request(options, function (error, response, body) {

        //deal with hebrew encoding
        csvString = encoding.convert(body, 'UTF8', "CP1255").toString();

Then for I switch encoding from CP1255 (=windows1255) to UTF8.

Hope it helps :)



来源:https://stackoverflow.com/questions/34150253/converting-from-windows-1255-to-utf-8-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!