在Node JS中从Windows-1255转换为UTF-8 [英] Converting from Windows-1255 to UTF-8 in Node JS

查看:466
本文介绍了在Node JS中从Windows-1255转换为UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Node.js从Windows-1255编码的网页中提取文本。我正在尝试使用以下Windows-1255编码器/解码器解码文本:
https ://www.npmjs.com/package/windows-1255

I'm extracting text from a Windows-1255-encoded webpage using Node.js. I'm trying to decode the text using the following Windows-1255 encoder/decoder: https://www.npmjs.com/package/windows-1255

在使用NPM安装它并在相关文件中要求它之后,我尝试使用它像这样:

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 ideas as to why?

谢谢!

Maor

推荐答案

不知道你是否仍然等待关于这个问题的答案,但以下工作对我...

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

当获取数据(文件)时,我将编码的get选项设置为二进制:

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();

> CP1255 (= windows1255 )到 UTF8

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

希望它有帮助:)

这篇关于在Node JS中从Windows-1255转换为UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆