-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
80 lines (69 loc) · 2.03 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var express = require('express');
var request = require('request');
var cheerio = require('cheerio');
var app = express();
app.route('/api/:lang').get((req, res) => {
const requestedLang = req.params['lang'];
switch(requestedLang) {
case 'mx':
url = 'https://www.socialbakers.com/statistics/facebook/pages/total/mexico/';
break;
case 'es':
url = 'https://www.socialbakers.com/statistics/facebook/pages/total/spain/';
break;
case 'us':
url = 'https://www.socialbakers.com/statistics/facebook/pages/total/united-states/';
break;
default:
res.send({ country: "not data found" });
}
request(url, function(err, resp, html){
if(!err){
var $ = cheerio.load(html);
var scope = {
pagehead: "",
audience: [],
growing: [],
top: []
};
$('.page-head h1').filter(function(){
var data = $(this);
rating = data.text().trim();
scope.pagehead = rating;
});
$(".top-fans-stats .item").each(function(i, item){
scope.audience.push({
title: $("h3 span", item).text().trim(),
totalfans: $("strong", item).text().trim(),
img: $(".top-fans-stats-img img").attr('src')
});
});
$('.graph-growing-list li').each(function(i, item){
scope.growing.push({
title: $("a h3", item).text().trim(),
growing: $("strong", item).text().trim(),
img: $("a .placeholder-img img").attr('src')
});
});
$('.graph-growing-list .block-1 li').each(function(i, item){
scope.growing.push({
//title: $("a h3", item).text().trim(),
//growing: $("strong", item).text().trim(),
//img: $("a img").attr('src')
});
});
$('.global-and-local .brand-table-placeholder table tr name').each(function(i, item){
console.log($(".item a").attr('title'));
console.log($(".item a .placeholder-img img").attr('src'));
});
res.send(scope);
}else{
res.send({
opps: 'algo salio mal'
});
}
});
});
app.listen('8081')
console.log('api on port 8081');
exports = module.exports = app;