From df1680903df0587de00e432ce6dc5a7d00566704 Mon Sep 17 00:00:00 2001 From: Jim Jiang Date: Mon, 9 Sep 2019 10:59:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=B9=E8=BF=9B=E5=B9=BF=E4=B8=9C?= =?UTF-8?q?=E5=B7=A5=E4=B8=9A=E5=A4=A7=E5=AD=A6=E6=A0=A1=E5=86=85=E6=96=B0?= =?UTF-8?q?=E9=97=BB=E7=BD=91=E7=9A=84=E8=BF=94=E5=9B=9E=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E3=80=82=20(#3026)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去除了文章内容中的“单 位:XXXXXX”文字 --- lib/routes/universities/gdut/news.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/routes/universities/gdut/news.js b/lib/routes/universities/gdut/news.js index 029797177..ab9d21425 100644 --- a/lib/routes/universities/gdut/news.js +++ b/lib/routes/universities/gdut/news.js @@ -125,8 +125,15 @@ module.exports = async (ctx) => { const $ = cheerio.load(response.data); // 文字内容 const content = $('#articleBody').html(); - const offset = content.indexOf(''); // 删除标题 - const description = content.substr(offset + 9).trim(); + let offset = content.indexOf(''); // 删除标题 + let description = content.substr(offset + 9).trim(); + + // 删除“单 位:XXXXXX” + const startIndex = description.indexOf('单 位:') + 4; + if (startIndex > 0 && startIndex < 50) { + offset = description.indexOf('
', 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); })