forked from soumilshah1995/ImageHunterNodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
39 lines (25 loc) · 866 Bytes
/
script.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
// Web Scrapping using Node js and Cherio Request
// npm install cherio
// npm install request
// Imports
const cherio = require('cherio');
const request = require('request');
const fs = require('fs');
// Create a Write Stream
var WriteStream = fs.createWriteStream("ImagesLink.txt", "UTF-8");
request('https://www.bridgeport.edu/', (err, resp, html)=>{
if(!err && resp.statusCode == 200){
console.log("Request was success ");
// Define Cherio or $ Object
const $ = cherio.load(html);
$("img").each((index, image)=>{
var img = $(image).attr('src');
var baseUrl = 'https://www.bridgeport.edu';
var Links = baseUrl + img;
WriteStream.write(Links);
WriteStream.write("\n");
});
}else{
console.log("Request Failed ");
}
});