-
Notifications
You must be signed in to change notification settings - Fork 54
/
dedicatedbrand.js
52 lines (45 loc) · 1.15 KB
/
dedicatedbrand.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
const axios = require('axios');
const cheerio = require('cheerio');
const {'v5': uuidv5} = require('uuid');
/**
* Parse webpage restaurant
* @param {String} data - html response
* @return {Object} restaurant
*/
const parse = data => {
const $ = cheerio.load(data);
return $('.productList-container .productList')
.map((i, element) => {
const link = `https://www.dedicatedbrand.com${$(element)
.find('.productList-link')
.attr('href')}`;
return {
link,
'brand': 'dedicated',
'price': parseInt(
$(element)
.find('.productList-price')
.text()
),
'name': $(element)
.find('.productList-title')
.text()
.trim()
.replace(/\s/g, ' '),
'photo': $(element)
.find('.productList-image img')
.attr('src'),
'_id': uuidv5(link, uuidv5.URL)
};
})
.get();
};
module.exports.scrape = async url => {
const response = await axios(url);
const {data, status} = response;
if (status >= 200 && status < 300) {
return parse(data);
}
console.error(status);
return null;
};