-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
82 lines (70 loc) · 2.31 KB
/
app.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const cheerio = require('cheerio');
const axios = require("axios");
const cors = require("cors");
app.use(
express.urlencoded(),
cors({
origin: 'http://localhost:3000'
})
);
server.listen(3000);
app.get('/altin', async (req, res) => {
var results = [];
try {
const url = "https://altin.doviz.com/gram-altin";
const { data } = await axios.get(url);
const $ = cheerio.load(data);
$("body > div.wrapper > div.kur-page > div.article-content > div.value-table > div > table > tbody > tr").each((index, element) => {
var name = $(element).find("td:nth-child(1)").text();
var buy = $(element).find("td:nth-child(2)").text();
var sell = $(element).find("td:nth-child(3)").text();
if (name.trim()) {
results.push({
name: name.trim(),
buy: buy.trim(),
sell: sell.trim()
});
}
});
} catch (err) {
console.error(err);
}
res.json({
"message": "success",
"data": results
})
});
app.get('/gumus', async (req, res) => {
var results = [];
try {
const url = "https://altin.doviz.com/gumus";
const { data } = await axios.get(url);
const $ = cheerio.load(data);
$("body > div.wrapper > div.kur-page > div.article-content > div.value-table > div > table > tbody > tr").each((index, element) => {
var name = $(element).find("td:nth-child(1)").text();
var buy = $(element).find("td:nth-child(2)").text();
var sell = $(element).find("td:nth-child(3)").text();
var m = $(element).find("td:nth-child(4)").text();
var m2 = $(element).find("td:nth-child(5)").text();
if (name.trim()) {
results.push({
name: name.trim(),
buy: buy.trim(),
sell: sell.trim(),
m: m.trim(),
m2: m2.trim(),
});
}
});
} catch (err) {
console.error(err);
}
res.json({
"message": "success",
"data": results
})
});