-
Notifications
You must be signed in to change notification settings - Fork 7
/
scrape.js
30 lines (26 loc) · 1016 Bytes
/
scrape.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
//this module returns a promise after scraping the notice board of the website.
const cheerio = require('cheerio');
const request = require('request');
function scrapeNoticeBoard(){
return new Promise(resolve=>{
request({
method:'GET',
url:'http://heritageit.edu/'
},(err,res)=>{
if(err){
console.log(err);
}else{
var $ = cheerio.load(res.body);
var notices = [];
$('#notice table tbody tr td table tbody ').children('tr').each((i,el)=>{
var title = $(el).find('td span').eq(0).text();
var a = $(el).find('a');
var link = $(a).attr('href');
notices[i] = {title:title,link:link};//array of objects to store notice data
});
resolve(notices);//promise returned
}
});
});
}
module.exports = scrapeNoticeBoard();