-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
58 lines (53 loc) · 1.67 KB
/
server.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
var cheerio = require('cheerio');
var request = require('request');
var express = require('express');
var app = express();
app.get('/:platform', function (req, res) {
var platform = "";
switch (req.params.platform) {
case 'ps4':
platform = 'ps4';
break;
case 'xbone':
platform = 'xbox-one';
case 'switch':
platform = 'switch';
case 'pc':
platform = 'pc';
default:
break;
}
request({
method: 'GET',
url: `https://gematsu.com/c/${platform}`
}, function (err, response, body) {
if (err) return console.error(err);
// Tell Cherrio to load the HTML
$ = cheerio.load(body);
let articulos = {
articles: []
};
$('.blog_list_post_style').each(function (index, element) {
article = $(element).find('#post-title').text()
articleURL = $(element).find('#post-title>a').attr('href')
tags = []
$(this).find('.post-category-color-text').each(function (index, post) {
tags[index] = $(this).text()
})
console.log(tags)
articulos.articles.push({
articleURL: articleURL,
description: article,
tags: tags
})
});
res.end(JSON.stringify(articulos));
});
})
app.get('/', function(req, res) {
res.end("Ruta no valida, introducir la plataforma en la URL. ej: 'http://localhost:8081/ps4'")
})
var server = app.listen(8081, function () {
var port = server.address().port
console.log("Example app listening at http://localhost:" + port)
})