-
Notifications
You must be signed in to change notification settings - Fork 2
/
negociosScraper.js
33 lines (30 loc) · 1.27 KB
/
negociosScraper.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
const rp = require('request-promise');
const fs = require('fs');
const cheerio = require('cheerio');
const url = 'https://www.jornaldenegocios.pt/noticias-no-minuto';
rp(url)
.then(function(html){
const $ = cheerio.load(html);
const articles = [];
for (let i = 0; i < 10; i++) {
const articleTitle = $('.listagem_destaques article.destaque > .text_container a:first-child').eq(i);
//const articleUrl = $('listagem_destaques article.destaque > .text_container a:first-child', html)[i];
const articleDate = $('.listagem_destaques article.destaque > .text_container .data_autor > .time').eq(i);
//articles.push(articleTitle.text());
//articles.push(articleUrl.attr('href'));
const dateTrim = articleDate.text().trim();
let thisYear = new Date();
let newDate = `${thisYear.getFullYear()}-${thisYear.getMonth() + 1}-${thisYear.getDate()}T${dateTrim}:00.000Z`;
articles.push(newDate);
}
console.log(articles);
/*
const jsonString = JSON.stringify(Object.assign({}, articles))
fs.writeFile('negocios2.json', jsonString, function(err){
console.log('File successfully written! - Check your project directory for the negocios2.json file');
});
*/
})
.catch(function(err){
console.log(err);
});