From ab82329171daf764444736ade51cb569d124c860 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Sat, 25 Jan 2020 01:46:58 +0100 Subject: [PATCH] Improved q so missing date element returns null. --- src/actors.js | 17 +++++++++++------ src/utils/q.js | 8 +++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/actors.js b/src/actors.js index 0483c2e2..fd62f11b 100644 --- a/src/actors.js +++ b/src/actors.js @@ -339,13 +339,18 @@ async function scrapeActors(actorNames) { const sources = argv.sources ? argv.sources.map(source => [source, scrapers.actors[source]]) : Object.entries(scrapers.actors); const profiles = await Promise.map(sources, async ([scraperSlug, scraper]) => { - const profile = await scraper.fetchProfile(actorEntry ? actorEntry.name : actorName); + try { + const profile = await scraper.fetchProfile(actorEntry ? actorEntry.name : actorName); - return { - ...profile, - name: actorName, - scraper: scraperSlug, - }; + return { + ...profile, + name: actorName, + scraper: scraperSlug, + }; + } catch (error) { + console.log(scraperSlug, error); + return null; + } }); const profile = await mergeProfiles(profiles, actorEntry); diff --git a/src/utils/q.js b/src/utils/q.js index 8b4ec345..9ce8b1f1 100644 --- a/src/utils/q.js +++ b/src/utils/q.js @@ -7,9 +7,9 @@ function q(context, selector, attrArg, trim = true) { const attr = attrArg === true ? 'textContent' : attrArg; if (attr) { - const value = context.querySelector(selector)[attr]; + const value = context.querySelector(selector)?.[attr]; - return trim ? value.trim() : value; + return trim ? value?.trim() : value; } return context.querySelector(selector); @@ -26,7 +26,9 @@ function qall(context, selector, attrArg, trim = true) { } function qdate(context, selector, format, match, attr = 'textContent') { - const dateString = context.querySelector(selector)[attr]; + const dateString = context.querySelector(selector)?.[attr]; + + if (!dateString) return null; if (match) { const dateStamp = dateString.match(match);