feat: 改进广东工业大学校内新闻网的返回内容格式。 (#3026)

去除了文章内容中的“单 位:XXXXXX”文字
This commit is contained in:
Jim Jiang
2019-09-09 10:59:55 +08:00
committed by DIYgod
parent b992171ff9
commit df1680903d
+10 -2
View File
@@ -125,8 +125,15 @@ module.exports = async (ctx) => {
const $ = cheerio.load(response.data);
// 文字内容
const content = $('#articleBody').html();
const offset = content.indexOf('</center>'); // 删除标题
const description = content.substr(offset + 9).trim();
let offset = content.indexOf('</center>'); // 删除标题
let description = content.substr(offset + 9).trim();
// 删除“单 位:XXXXXX”
const startIndex = description.indexOf('单 位:') + 4;
if (startIndex > 0 && startIndex < 50) {
offset = description.indexOf('<br>', startIndex) + 4;
description = description.substr(offset).trim();
}
// 获取文章数据
const articleinfos = $('.articleinfos').text();
@@ -142,6 +149,7 @@ module.exports = async (ctx) => {
author: author,
category: category,
};
// 将文章结果缓存
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})