From 967492dcaa66a07dab2641141465bb3dcba6e10d Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Wed, 13 Jul 2022 20:02:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E4=B8=8A=E6=B5=B7=E5=B8=82?= =?UTF-8?q?=E8=8D=AF=E5=93=81=E7=9B=91=E7=9D=A3=E7=AE=A1=E7=90=86=E5=B1=80?= =?UTF-8?q?=20(#10205)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/gov/shanghai/yjj/index.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/v2/gov/shanghai/yjj/index.js b/lib/v2/gov/shanghai/yjj/index.js index a105116aa3..353984fb5a 100644 --- a/lib/v2/gov/shanghai/yjj/index.js +++ b/lib/v2/gov/shanghai/yjj/index.js @@ -21,25 +21,31 @@ module.exports = async (ctx) => { .map((item) => { item = $(item); + const link = item.attr('href'); + return { title: item.text(), - link: `${rootUrl}${item.attr('href')}`, pubDate: parseDate(item.next().text()), + link: /^http/.test(link) ? link : `${rootUrl}${link}`, }; }); items = await Promise.all( items.map((item) => ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); + try { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); - const content = cheerio.load(detailResponse.data); + const content = cheerio.load(detailResponse.data); - item.description = content('#ivs_content').html(); - item.pubDate = timezone(parseDate(content('meta[name="pubdate"]').attr('content')), +8); + item.description = content('#ivs_content').html(); + item.pubDate = timezone(parseDate(content('meta[name="pubdate"]').attr('content')), +8); + } catch (e) { + // no-empty + } return item; })