-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.js
48 lines (41 loc) · 1.49 KB
/
list.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
const arvish = require('arvish');
const cheerio = require('cheerio');
const got = require('got');
const listAPI = `https://eshop-prices.com/games?q={query}¤cy=${process.env.currency}`;
got(listAPI.replace('{query}', arvish.input), {
headers: {
'Content-Type': 'text/html; charset=utf-8',
'Accept': '*/*',
"Accept-Encoding": "gzip, deflate, br",
'Connection': 'gzip, deflate, br',
'Cache-Control': 'no-cache'
},
}).then((html) => {
const $ = cheerio.load(html.body);
const listElems = $('.games-list').children('.games-list-item');
const items = [];
for (const elem of listElems) {
if (!elem.attribs.href) continue;
const gameChilds = elem.children;
let title;
let icon;
let subtitle;
const arg = elem.attribs.href;
for (const gameChild of gameChilds) {
if (!gameChild.attribs) continue;
if (gameChild.attribs.class === 'games-list-item-content') {
subtitle = $(gameChild).children('.games-list-item-description').text();
title = $($(gameChild).children('.games-list-item-title').children()[0]).text();
} else if (gameChild.attribs.class === 'games-list-item-image') {
icon = $($(gameChild).children('picture').children().last()).attr().src;
}
}
items.push({
title,
subtitle,
icon,
arg
});
}
arvish.output(items);
});