-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (49 loc) · 1.63 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
57
const express = require('express')
const axios = require("axios")
const cheerio = require("cheerio")
const { json } = require('body-parser')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.get("/newarrivals", async function(req, res) {
let newArrival = await ExtractData('newArrival');
res.send(newArrival);
});
app.get("/featureproducts", async function(req, res) {
let newArrival = await ExtractData('featureProducts');
res.send(newArrival);
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
async function ExtractData(type)
{
let website = await axios.get('https://technext.github.io/furn./');
let data=[];
var $ = cheerio.load(website.data);
switch (type) {
case 'newArrival':
$('.single-new-arrival').each(function (index, element) {
let product = $(this).find('h4 >a ');
let price = $(this).find('.arrival-product-price');
data.push({
'product' : $(product).text(),
'price' : $(price).text()
});
});
break;
case 'featureProducts':
$('.single-feature-txt').each(function (index, element) {
let product = $(this).find('h3 >a ');
let price = $(this).find('h5');
data.push({
'product' : $(product).text(),
'price' : $(price).text()
});
});
break;
}
return data;
}