-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (53 loc) · 1.85 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const fs = require('fs');
const request = require('request');
const cheerio = require('cheerio');
const subpages = require('./utils/subpages.js');
const getData = require('./utils/getData.js');
const mongodb = require('./mongodb.js');
const sections=['','sports','business']
console.log('Scrapping started!');
sections.forEach(ele => {
const url="https://www.firstpost.com/"+encodeURIComponent(ele);
request.get({url,gzip:true},(error,response,html)=>{
if(!error && response.statusCode===200){
const $=cheerio.load(html);
subpages($,(error,links)=>{
if(error){
return console.log(error);
}
links.forEach(url => {
if(url){
getData(url,(error,res)=>{
if(error){
return console.log(error);
}
const data={
title:res.title,
image:res.image,
content:res.content,
urls:res.urls,
}
mongodb.add(data,(error,response)=>{
if(error){
console.log(error);
}else{
console.log(response);
}
})
})
}
});
})
}else{
console.log(error);
}
})
});
//To delete DB
// mongodb.deleteDB(true,(error,response)=>{
// if(error){
// console.log(error);
// }else{
// console.log(response);
// }
// })