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() );