From 8a5dbbcc1f215f6a90d545b558f181baf5d6e949 Mon Sep 17 00:00:00 2001 From: EsuRt <15177069+EsuRt@users.noreply.github.com> Date: Mon, 13 Apr 2020 19:34:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=AD=E5=9B=BD=E6=94=BF=E5=BA=9C?= =?UTF-8?q?=E7=BD=91=E5=90=B9=E9=A3=8E=E4=BC=9A=E5=92=8C=E6=96=B0=E9=97=BB?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=A0=BC=E5=BC=8F=E8=B0=83=E6=95=B4=20(#4406?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/gov/news/index.js | 68 +++++++++++++++---------- lib/routes/gov/statecouncil/briefing.js | 12 ++--- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/lib/routes/gov/news/index.js b/lib/routes/gov/news/index.js index 806fd06db..48e6756db 100644 --- a/lib/routes/gov/news/index.js +++ b/lib/routes/gov/news/index.js @@ -55,37 +55,53 @@ module.exports = async (ctx) => { let fullTextGet = ''; if (item.html().search(/dysMiddleResultConItemTitle/g) !== -1) { contentUrl = item.find('a').attr('href'); - description = await ctx.cache.tryGet(contentUrl, async () => { - fullTextGet = await got.get(contentUrl); - fullTextData = cheerio.load(fullTextGet.data); - if (fullTextData.html().search(/pages_content/g) !== -1) { - return fullTextData('.pages_content').html(); - } else { - return fullTextData('#UCAP-CONTENT').html(); - } - }); + if (contentUrl.search(/content/g) === -1) { + description = item.find('a').text(); // 忽略获取吹风会的全文 + } else { + description = await ctx.cache.tryGet(contentUrl, async () => { + fullTextGet = await got.get(contentUrl); + fullTextData = cheerio.load(fullTextGet.data); + if (fullTextData.html().search(/pages_content/g) !== -1) { + fullTextData('.shuzi').remove(); // 移除videobg的图片 + fullTextData('#myFlash').remove(); // 移除flash + return fullTextData('.pages_content').html(); + } else { + fullTextData('.shuzi').remove(); // 移除videobg的图片 + fullTextData('#myFlash').remove(); // 移除flash + return fullTextData('#UCAP-CONTENT').html(); + } + }); + } } else { href = item.find('a').attr('href'); contentUrl = href.startsWith('/') ? `http://www.gov.cn${href}` : href; - description = await ctx.cache.tryGet(contentUrl, async () => { - fullTextGet = await got.get(contentUrl); - fullTextData = cheerio.load(fullTextGet.data); - const $1 = fullTextData.html(); - if (contentUrl.search(/zhengceku/g) !== -1) { - fullText = fullTextData('.pages_content').html(); - } else { - if ($1.search(/UCAP-CONTENT/g) === -1) { - fullText = fullTextData('body').html(); + if (contentUrl.search(/content/g) === -1) { + description = item.find('a').text(); // 忽略获取吹风会的全文 + } else { + description = await ctx.cache.tryGet(contentUrl, async () => { + fullTextGet = await got.get(contentUrl); + fullTextData = cheerio.load(fullTextGet.data); + const $1 = fullTextData.html(); + if (contentUrl.search(/zhengceku/g) !== -1) { + // 政策文件库 + fullText = fullTextData('.pages_content').html(); } else { - fullTextData('.shuzi').remove(); - fullText = fullTextData('#UCAP-CONTENT').html(); + if ($1.search(/UCAP-CONTENT/g) === -1) { + fullTextData('.shuzi').remove(); // 移除videobg的图片 + fullTextData('#myFlash').remove(); // 移除flash + fullText = fullTextData('body').html(); + } else { + fullTextData('.shuzi').remove(); // 移除videobg的图片 + fullTextData('#myFlash').remove(); // 移除flash + fullText = fullTextData('#UCAP-CONTENT').html(); + } } - } - const regImg = /(img src=")(.*)(".*)/g; - const regUrl = /(http.*\/)(content.*)/; - const urlSplit = contentUrl.replace(regUrl, '$1'); - return fullText.replace(regImg, '$1' + urlSplit + '$2' + '$3'); - }); + const regImg = /(img src=")(.*)(".*)/g; + const regUrl = /(http.*\/)(content.*)/; + const urlSplit = contentUrl.replace(regUrl, '$1'); + return fullText.replace(regImg, '$1' + urlSplit + '$2' + '$3'); // 处理图片链接 + }); + } } return { title: item.find('a').text(), diff --git a/lib/routes/gov/statecouncil/briefing.js b/lib/routes/gov/statecouncil/briefing.js index 73744602b..ecd5b79c8 100644 --- a/lib/routes/gov/statecouncil/briefing.js +++ b/lib/routes/gov/statecouncil/briefing.js @@ -16,14 +16,14 @@ module.exports = async (ctx) => { .map(async (index, item) => { item = $(item); const contenlUrl = item.find('a').attr('href'); - const description = await ctx.cache.tryGet(contenlUrl, async () => { - const fullText = await got.get(contenlUrl); - const fullTextData = cheerio.load(fullText.data); - return fullTextData('.online_list').html(); - }); + // const description = await ctx.cache.tryGet(contenlUrl, async () => { + // const fullText = await got.get(contenlUrl); + // const fullTextData = cheerio.load(fullText.data); + // return fullTextData('.online_list').html(); + // }); return { title: item.find('a').text(), - description: description, + description: item.find('a').text(), link: contenlUrl, }; })