fix: bjnews issue #6180 (#6184)

This commit is contained in:
Laam Pui
2020-11-19 22:42:01 +00:00
committed by GitHub
parent 9bf4514411
commit ad88ade41b
+7 -5
View File
@@ -5,13 +5,13 @@ module.exports = async (ctx) => {
const url = `http://www.bjnews.com.cn/${ctx.params.cat}`;
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('#news_ul li').get();
const list = $('#waterfall-container .pin_demo > a').get();
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const time = $('p').text();
const title = $('a').text();
const title = $('.pin_tit').text();
const itemUrl = $('a').attr('href');
const cache = await ctx.cache.get(itemUrl);
if (cache) {
@@ -20,13 +20,15 @@ module.exports = async (ctx) => {
const responses = await got.get(itemUrl);
const $d = cheerio.load(responses.data);
$d('img').each((i, e) => $(e).attr('referrerpolicy', 'no-referrer'));
const single = {
title,
pubDate: new Date(time).toUTCString(),
pubDate: new Date($d('.left-info .timer').text()),
author: $d('.left-info .reporter').text(),
link: itemUrl,
guid: itemUrl,
description: $d('#main .content').html(),
description: $d('#contentStr').html(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);