-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
74 lines (63 loc) · 1.51 KB
/
main.js
File metadata and controls
74 lines (63 loc) · 1.51 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
//module app
var app = {
run: function () {
const
request = require('request'),
cheerio = require('cheerio'),
csv=require('csvtojson')
csvFilePath='list.csv'
;
function Web(name, url, sources) {
this.name = name;
this.url = url;
this.sources = sources;
}
var webs = [];
var readScripts = function (url) {
request(url, function (error, response, body) {
var $ = cheerio.load(body);
var srcs = [];
$('script').each(function () {
var src = $(this).attr('src');
if(src) {
srcs[srcs.length] = src;
}
});
})
}
var loadScriptSources = function(webs, onComplete) {
this.loaded= 0;
this.that = this;
webs.forEach((web, i, array) => {
request(web.url, (error, response, body) => {
var $ = cheerio.load(body);
var srcs = [];
$('script').each(function () {
var src = $(this).attr('src');
if(src) {
srcs[srcs.length] = src;
}
});
web.sources = srcs;
that.loaded++;
if(that.loaded == array.length) {
onComplete(webs);
}
});
});
}
var printWebs = function (webs) {
console.log('\n' + ' -------- PRINT WEBS -------- ' + '\n');
console.log(webs);
}
return csv()
.fromFile(csvFilePath)
.on('json',(jsonObj)=>{
webs[webs.length] = new Web(jsonObj.name, jsonObj.url);
})
.on('done',(error)=>{
return loadScriptSources(webs, printWebs);
})
}
}
app.run();