-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (40 loc) · 1.42 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
var request = require('request');
var cheerio = require('cheerio');
var express = require('express');
var app = express();
// set the port of our application
// process.env.PORT lets the port be set by Heroku
var port = process.env.PORT || 8080;
function getRequest(response){
request('http://www.catho.com.br/vagas/por-cargo/view/profissional/51/', function(err, res, body) {
if (err) console.log('Erro: ' + err);
var $ = cheerio.load(body);
var list = [];
var total = 0;
$('td').each(function(index){
var title = $(this).find('h3').text();
var desc = $(this).find('span').text();
desc = desc.split(" ");
vagas = parseInt(desc[0]);
if (vagas > 100){
list.push({title: title, vagas: vagas});
total += vagas;
}
});
list = list.sort(function (a, b) { return b.vagas - a.vagas; });
for (var i in list){
var percent = list[i].vagas / total * 100;
percent = percent.toPrecision(2);
response.write("<li> " + i + " " + list[i].title + " - " + list[i].vagas + " vagas >> " + percent + "% </li>");
}
response.end("</ul> Total: " + total + " vagas");
});
}
app.get('/', function (req, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
response.write("<h2>Catho Crawler</h2><ul>");
getRequest(response);
});
app.listen(port, function () {
console.log('App listening on port ' + port + '!');
});