N
N
Nikita_Migushev2021-03-11 19:22:09
Node.js
Nikita_Migushev, 2021-03-11 19:22:09

How to recognize Russian when receiving XML in nodejs?

Good afternoon.

I'm trying to get exchange rates from cbr. As a result, I get XML with unrecognized Cyrillic. Where should I write it, please?

The code

const xml2js = require('xml2js');
const util = require('util');

const parser = new xml2js.Parser();

var http = require('http');

//The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
var options = {
  host: 'www.cbr.ru',
  path: '/scripts/XML_daily.asp?date_req=02/03/2002'
};

callback = function(response) {
  var str = '';

  //another chunk of data has been received, so append it to `str`
  response.on('data', function (chunk) {
    str += chunk;
  });

  //the whole response has been received, so we just print it out here
  response.on('end', function () {
    parser.parseString(str, (err, result) => {
        console.log(util.inspect(result, false, null, true));
    })
  });
}

http.request(options, callback).end();


Result
604a43a247ccf710639086.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2018-01-11
@ivigamberdiev

Getting a task from the cart - nginx-uwsgi-(django / flask / handmade wsgi )
Depending on how long the parser works
- start it in the same thread that received the request from the user
- create a queue (celery) and work through it

A
Artem Sovetnikov, 2018-01-11
@Sovetnikov

If it happens that parsers fall (and they certainly fall), then celery is unambiguous.
More complex workflows - dask.distributed. Celery canvas is very limited.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question