-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
56 lines (42 loc) · 1.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var express = require('express');
var app = express();
var cheerio = require('cheerio');
var request = require('request');
app.use(express.static('public'));
app.use('/node_modules', express.static('node_modules'));
app.get('/indices/selic', function (req, res) {
request('https://www.melhorcambio.com/taxa-selic', function (error, response, body) {
console.log('statusCode:', response && response.statusCode);
const $ = cheerio.load(body);
var v = $("#snipet-div > table > tbody > tr:nth-child(4) > td.tdvalor").text();
res.send(v.replace(',','.').replace('%',''));
});
});
app.get('/indices/ipca', function (req, res) {
request('https://www.portalbrasil.net/ipca/', function (error, response, body) {
console.log('statusCode:', response && response.statusCode);
const $ = cheerio.load(body);
var v = $(".fd17 > div:nth-child(2) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > table:nth-child(1) > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(4)").text();
res.send(v.replace(',','.'));
});
});
app.get('/indices/poupanca', function (req, res) {
request('https://www.portalbrasil.net/rendimentos-da-caderneta-de-poupanca-mensal-2022/', function (error, response, body) {
console.log('statusCode:', response && response.statusCode);
const $ = cheerio.load(body);
var v = $("#tb > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(2)").text();
res.send(v.replace(',','.'));
});
});
app.get('/indices/cdi', function (req, res) {
request('https://www.melhorcambio.com/taxa-selic', function (error, response, body) {
console.log('statusCode:', response && response.statusCode);
const $ = cheerio.load(body);
var v = $("#snipet-div > table > tbody > tr:nth-child(4) > td.tdvalor").text();
res.send(v.replace(',','.').replace('%',''));
});
});
const _PORT = 9000;
app.listen(_PORT, function () {
console.log('Ok!', _PORT);
});