-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
103 lines (88 loc) · 2.67 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
require('es6-promise').polyfill();
var request = require('request');
var cheerio = require('cheerio');
const urlBase = 'https://sites.google.com/a/fabio.co/lista-base/';
const urlBase2 = 'https://sites.google.com/a/fabio.co/lista-propria/';
const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9';
exports.naoTestamEmAnimais = function() {
return new Promise(function(accept, error) {
var options = {
url: urlBase2,
headers: {
'User-Agent': userAgent
}
};
request(options, function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var titles = []
var produto = {};
var produtos = [];
$('thead').each(function(i, element){
$(element).children().each(function(j, subElement) {
$(subElement).children().each(function(k, subSubElement) {
var title = $(subSubElement).text();
titles[k] = String(title).replace(/'/g, '');
});
});
});
var x = 0;
$('tbody tr.goog-ws-list-tableRow').each(function(i, element){
produto['id'] = i
$(element).children().each(function(j, subElement) {
var propriedade = String($(subElement).text()).replace(/2/g, '2')
produto[titles[j]] = propriedade.slice(0, -1)
});
produtos[x] = produto;
produto = {};
x++;
});
accept(JSON.stringify(produtos));
} else {
error({ error:"Não foi possível retornar as informações!" });
}
});
});
};
exports.testamEmAnimais = function() {
return new Promise(function(accept, error) {
var options = {
url: urlBase,
headers: {
'User-Agent': userAgent
}
};
request(options, function(error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var titles = []
var produto = {};
var produtos = [];
$('thead').each(function(i, element){
$(element).children().each(function(j, subElement) {
$(subElement).children().each(function(k, subSubElement) {
var title = $(subSubElement).text();
titles[k] = String(title).replace(/'/g, '');
});
});
});
var x = 0;
$('tbody tr.goog-ws-list-tableRow').each(function(i, element){
produto['id'] = i
$(element).children().each(function(j, subElement) {
var propriedade = String($(subElement).text()).replace(/2/g, '2')
produto[titles[j]] = propriedade.slice(0, -1)
});
produtos[x] = produto;
produto = {};
x++;
});
//console.log(produtos.length);
accept(JSON.stringify(produtos));
} else {
error({ error:"Não foi possível retornar as informações!" });
}
});
});
};