-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
35 lines (30 loc) · 1.09 KB
/
parser.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
const cheerio = require('cheerio');
/**
* Parse HTML to list of app object
* @param {string} html html string
* @return {Array} Array of apps
*/
function parser(html) {
try {
const $ = cheerio.load(html);
const list = [];
$('#SearchResultsListings > div > div').each(async (index, e) => {
const app = {};
app.title = $(e).find('a > h4').text();
app.author = $(e).find('div.ui-app-card__by-line > div').text().split(' ')[1];
app.desc = $(e).find('p').text();
app.rating = $(e).find('div.ui-app-card__review > div > div.ui-star-rating__text > span.ui-star-rating__rating').text().split(' ')[0];
app.reviews = $(e).find('div.ui-app-card__review > div > div.ui-star-rating__text > span.ui-review-count-summary').text();
const regex = /\d*/g;
app.reviews = app.reviews.match(regex)[1];
app.pricing = $(e).find('div.ui-app-card__context > div > div').text();
app.url = $(e).find('div > a').attr('href');
list.push(app);
});
return list;
} catch (error) {
console.log(error);
return [];
}
}
module.exports = parser;