I am trying to parse out the date and full URL from articles.
const cheerio = require('cheerio');
const request = require('request');
const resolveRelative = require('resolve-relative-url');
request('https://www.moneyweb.co.za/', function (error, response, html) {
if (!error && response.statusCode == 200) {
const $ = cheerio.load(html);
$('.border0010-dotted').each(function (i, element) {
const title = $(this).find('.title').text().trim()
const url = resolveRelative($(this).find('.a href').text().trim(), response.request.uri.href)
const date = $(this).attr('.inline-block')
const description = $(this).find('.excerpt').text().trim()
const feedItem = {
title: title,
description: description,
url: url,
date: date
}
console.log(feedItem)
})
}
});
This is an example output:
{ title: 'Hiring a new bank CEO rarely improves the share price',
description: 'New CEOs have done little to boost Europe bank stocks.',
url: 'https://www.moneyweb.co.za/',
date: undefined }
Any suggestions on how I can retrieve the date and full URL?