var cheerio = require("cheerio")
let axios=require("axios")
let _=require("lodash")
function fetchCongressMenCSpanVideos(cspan_id) {
return new Promise((resolve, reject) => {
//get our html
//var url="https://www.c-span.org/person/?berniesanders"
axios.get(`http://www.c-spanvideo.org/person/${cspan_id}`)
.then(resp => {
//html
const html = resp.data;
//load into a $
const $ = cheerio.load(html);
//find ourself a img
const videos = $("#recent-appearances").find("li").map(function(i, elem) {
// fruits[i] = $(this).text();
return {
url:$(this).find("a").attr('href'),
thumb:$(this).find("img").attr('src'),
date:$(this).find("time").text(),
title:$(this).find("h3").text(),
description:$(this).find("p").text()
}
}).get();
resolve(videos);
})
.catch(err => {
reject(err);
});
});
}
let cspan_id="994"//bernie sanders
fetchCongressMenCSpanVideos().then(x=>console.log(x))