fix(route): 修正北京教育考试院内容提取错误 (#8209)

This commit is contained in:
erriy 2021-11-27 15:51:26 +08:00 committed by GitHub
parent 8518a5fc95
commit fdba2d7d7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 6 deletions

View File

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