From 0cf12554b0165ae26d45098ea718a960f270eb5b Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Mon, 22 Jun 2020 04:43:52 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=96=B7=E5=9A=8F=20DOM=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=20(#5022)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/dapenti/utils.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/routes/dapenti/utils.js b/lib/routes/dapenti/utils.js index 83d2c2ad4..b1d5a81fb 100644 --- a/lib/routes/dapenti/utils.js +++ b/lib/routes/dapenti/utils.js @@ -35,14 +35,24 @@ module.exports = { responseType: 'buffer', }); const convert_data = iconv.decode(original_data.data, 'gbk'); - const detail_data = cheerio - .load(convert_data, { - decodeEntities: false, - })('div[class="oblog_text"]') - .html(); + const description = cheerio.load(convert_data, { + decodeEntities: false, + })('body > table > tbody > tr > td.oblog_t_2 > div > table > tbody > tr:nth-child(2) > td'); + description.find('table, .adsbygoogle').remove(); + + // remove header + const count = subjectid.toString() === '70' ? 8 : 3; + for (let index = 0; index < count; index++) { + description.children().first().remove(); + } + + // remove footer + for (let index = 0; index < 8; index++) { + description.children().last().remove(); + } const single = { title: el.text(), - description: detail_data, + description: description.html(), link: url, }; return Promise.resolve(single);