Skip to content

Commit

Permalink
fix(route): 纽约时报 - 新闻简报 图片缺失 (DIYgod#7841)
Browse files Browse the repository at this point in the history
  • Loading branch information
auto-bot-ty authored Jul 17, 2021
1 parent 41a5170 commit 22789fd
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/routes/nytimes/daily_briefing_chinese.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,26 @@ module.exports = async (ctx) => {
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const response = await got.get(item.link);
const $ = cheerio.load(response.data);
const data = response.data;
const arr = data.match(/"url":"https:\\u002F\\u002Fstatic(\S*)"articleLarge"/g);
const imageLink = arr.map((e) => JSON.parse(`{${e}}`).url);

const $ = cheerio.load(data);
$('.css-pncxxs.etfikam0').remove();
$('.css-1xdhyk6.erfvjey0').each((_, item) => {
item = $(item);
const link = item.find('img').attr('src');
item.replaceWith(`<img src="${link}">`);
// remove 'Credit...'
$('.css-1ly73wi.e1tej78p0').remove();
$('.css-1xdhyk6.erfvjey0').each((i, e) => $(e).replaceWith(`<img src="${imageLink[i]}">`));

$('.css-1l44abu.ewdxa0s0').each((i, e) => {
const figureNote = $(e)
.children()
.map((i, e) => $(e).text())
.get();
$(e).replaceWith(`<p><small>${figureNote.join(' ')}</small><p>`);
});
const date = $('time').attr('datetime');

item.description = $('.meteredContent.css-1r7ky0e').html();
const date = $('.css-x7rtpa.e16638kd0').attr('datetime');
item.pubDate = parseDate(date);
return item;
})
Expand Down

0 comments on commit 22789fd

Please sign in to comment.