-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.js
More file actions
91 lines (74 loc) · 2.32 KB
/
Copy pathget.js
File metadata and controls
91 lines (74 loc) · 2.32 KB
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
const https = require('https');
const fs = require('fs');
const cheerio = require('cheerio');
const util = require('util');
let $;
const BASE_URL = "https://scholar.google.com.br";
const URL_ORGANIZACAO = "/citations?view_op=view_org&hl=en&org=";
const NUM_MAX_PESQUISADORES = 5000;
const ORGANIZACAO = {
id: "13217906292402142721",
nome: "Universidade Federal do ABC",
sigla: "UFABC"
};
/*const ORGANIZACAO = {
id: "4833850012421173011",
nome: "Universidade de São Paulo",
sigla: "USP"
};*/
async function getRequest(url){
return new Promise((resolve, reject) => {
https.get(url, res => {
res.setEncoding("binary");
let body = "";
res.on('data', (data) => body += data);
res.on('end', () => {
resolve(body);
});
res.on('error', (e) => reject(e));
}).on('error', (e) => reject(e));
});
}
async function organizacaoParaJSON(body, json){
return new Promise((resolve, reject) => {
$ = cheerio.load(body);
let pesquisadores = $(".gsc_oai_name > a").toArray();
let proximaPagina = $(".gs_btnPR").attr("onclick");
if(proximaPagina != null){
proximaPagina = proximaPagina
.replace("window.location='", "")
.replace("'", "")
.replace(/\\x3d/g, "=")
.replace(/\\x26/g, "&");
}
json.proximaPagina = proximaPagina;
for(let i = 0; i < pesquisadores.length; i++){
json.pesquisadores.push({
nome : pesquisadores[i].children[0].data,
url : $(pesquisadores[i]).attr("href")
});
}
resolve(json);
});
}
async function bora(){
let d = new Date(Date.now());
let dados = {
id: ORGANIZACAO.id,
nome: ORGANIZACAO.nome,
sigla: ORGANIZACAO.sigla,
dataCriacao: d.toJSON();
ultimoUpdate: d.toJSON(),
proximaPagina: URL_ORGANIZACAO + ORGANIZACAO.id,
pesquisadores: []
};
while(dados.proximaPagina != null && dados.pesquisadores.length < NUM_MAX_PESQUISADORES){
console.log("Path: " + dados.proximaPagina + "\n" + "#Pesquisadores: " + dados.pesquisadores.length + "\n");
let resposta = await getRequest(BASE_URL + dados.proximaPagina);
dados = await organizacaoParaJSON(resposta, dados);
}
console.log("Acabou. #Pesquisadores obtidos: " + dados.pesquisadores.length);
let nome = `${dados.sigla}_${d.toDateString()}(${d.getHours()}h${d.getMinutes()}min${d.getMinutes()}s).json`;
fs.writeFile("dados/" + nome, JSON.stringify(dados), (e) => {if(e) console.error(e)});
}
bora();