-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (33 loc) · 827 Bytes
/
app.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
var http = require('http'),
cheerio = require('cheerio');
var args = process.argv;
var url = process.argv[2].substring(7);
var options = {
host:url,
port:80,
path:'/',
method:'GET'
}
if (args.length < 3) {
console.log('Too few argument.');
} else {
if (args.length > 3) {
console.log("Too many argument. The first input will be used.")
}
var req = http.request(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.setEncoding('utf8');
res.on('data', function (chunk) {
$ = cheerio.load(chunk);
images = $("img");
for (var i=0; i<images.length; i++) {
console.log(images[i].attribs.src);
}
});
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
});
req.end();
}