mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): 壹蘋新聞網獲取失敗 (#10697)
* fix(route): 壹蘋新聞網獲取失敗 * fix(route): rate limit
This commit is contained in:
@@ -1,40 +1,40 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const cheerio = require('cheerio');
|
||||
const asyncPool = require('tiny-async-pool');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category ?? 'new';
|
||||
const currentUrl = `https://tw.nextapple.com/realtime/${category}`;
|
||||
const response = await got(currentUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const items = await Promise.all(
|
||||
$('article')
|
||||
.get()
|
||||
.map((item) => {
|
||||
const link = $(item).find('.post-title').attr('href');
|
||||
return ctx.cache.tryGet(link, async () => {
|
||||
const response = await got(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const mainContent = $('#main-content');
|
||||
const titleElement = mainContent.find('header h1');
|
||||
const title = titleElement.text();
|
||||
titleElement.remove();
|
||||
const postMetaElement = mainContent.find('.post-meta');
|
||||
const category = postMetaElement.find('.category').text();
|
||||
const pubDate = parseDate(postMetaElement.find('time').attr('datetime'));
|
||||
postMetaElement.remove();
|
||||
$('.post-comments').remove();
|
||||
const items = [];
|
||||
for await (const item of asyncPool(5, $('article.infScroll'), (item) => {
|
||||
const link = $(item).find('.post-title').attr('href');
|
||||
return ctx.cache.tryGet(link, async () => {
|
||||
const response = await got(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
const mainContent = $('#main-content');
|
||||
const titleElement = mainContent.find('header h1');
|
||||
const title = titleElement.text();
|
||||
titleElement.remove();
|
||||
const postMetaElement = mainContent.find('.post-meta');
|
||||
const category = postMetaElement.find('.category').text();
|
||||
const pubDate = parseDate(postMetaElement.find('time').attr('datetime'));
|
||||
postMetaElement.remove();
|
||||
$('.post-comments').remove();
|
||||
|
||||
return {
|
||||
title,
|
||||
description: mainContent.html(),
|
||||
category,
|
||||
pubDate,
|
||||
link,
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
return {
|
||||
title,
|
||||
description: mainContent.html(),
|
||||
category,
|
||||
pubDate,
|
||||
link,
|
||||
};
|
||||
});
|
||||
})) {
|
||||
items.push(item);
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
|
||||
Reference in New Issue
Block a user