From fdba2d7d7b6ce850a4c85db329e30b51ced74d98 Mon Sep 17 00:00:00 2001 From: erriy Date: Sat, 27 Nov 2021 15:51:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E4=BF=AE=E6=AD=A3=E5=8C=97?= =?UTF-8?q?=E4=BA=AC=E6=95=99=E8=82=B2=E8=80=83=E8=AF=95=E9=99=A2=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=8F=90=E5=8F=96=E9=94=99=E8=AF=AF=20(#8209)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/gov/beijing/eea.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/routes/gov/beijing/eea.js b/lib/routes/gov/beijing/eea.js index 181bd5eda..5a50b7c48 100644 --- a/lib/routes/gov/beijing/eea.js +++ b/lib/routes/gov/beijing/eea.js @@ -17,7 +17,7 @@ async function load(link) { // 加载文章内容 const $ = cheerio.load(response.data); // 提取文章内容 - const description = $('.sidNavText').html(); + const description = $('div.info-txt').html(); // 返回解析的结果 return { description }; } @@ -37,7 +37,7 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); // 获取当前页面的 list - const list = $('div#info>ul>li'); + const list = $('ul.com-list>li'); const result = await Promise.all( // 遍历每一篇文章 @@ -57,7 +57,7 @@ module.exports = async (ctx) => { const $title = $('a').text(); // 获取每个的标题 - const date_txt = $.text().match(/[1-9]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])/); // 匹配 yyyy-mm-dd格式时间 + const date_txt = $('span').text(); // 匹配 yyyy-mm-dd格式时间 const $pubdate = new Date(date_txt); // 正则匹配发布时间 然后转换成时间 // 列表上提取到的信息 @@ -67,12 +67,19 @@ module.exports = async (ctx) => { pubDate: $pubdate, link: $item_url, guid: $item_url, + description: $title, }; // 对于列表的每一项, 单独获取 时间与详细内容 - const other = $is_interior ? await ctx.cache.tryGet($item_url, () => load($item_url)) : $title; - // 合并解析后的结果集作为该篇文章最终的输出结果 - return Promise.resolve(Object.assign({}, single, other)); + try { + // 文章可能存在404错误,错误则直接使用title当作内容 + const other = $is_interior ? await ctx.cache.tryGet($item_url, () => load($item_url)) : $title; + // 合并解析后的结果集作为该篇文章最终的输出结果 + return Promise.resolve(Object.assign({}, single, other)); + } + catch (e) { + return Promise.resolve(single); + } }) .get() );