feat: Add some error handling for when certain pieces of HTML a… (#3594)

This commit is contained in:
Logan Rockmore
2019-12-18 12:01:04 +08:00
committed by DIYgod
parent 36224c0a08
commit b0748e5e7c
+9 -5
View File
@@ -6,14 +6,18 @@ async function load(link) {
const response = await got.get(link);
const $ = cheerio.load(response.data);
const shotMedia = $('.media-shot').html();
const shotDescription = $('.shot-desc').html();
const shotMedia = $('.media-shot').html() || $('.main-shot').html() || '';
const shotDescription = $('.shot-desc').html() || '';
const shotViews = $('.shot-views').text() || '0 views';
const shotLikes = $('.shot-likes').text() || '0 likes';
const shotSaves = $('.shot-saves').text() || '0 saves';
const description = `${shotMedia}<br />
${shotDescription}<br />
${$('.shot-views').text()}<br />
${$('.shot-likes').text()}<br />
${$('.shot-saves').text()}`;
${shotViews}<br />
${shotLikes}<br />
${shotSaves}`;
const pubDateString = $('.shot-date').text();
const pubDate = new Date(pubDateString).toUTCString();