mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-10 15:21:59 +08:00
feat: add abc news (#5776)
Co-authored-by: codefactor-io <support@codefactor.io> Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
@@ -4,6 +4,20 @@ pageClass: routes
|
||||
|
||||
# News
|
||||
|
||||
## ABC News
|
||||
|
||||
### Site
|
||||
|
||||
<Route author="nczitzk" example="/abc" path="/abc/:site?" :paramsDesc="['Site, see below']">
|
||||
|
||||
Site
|
||||
|
||||
| Just In | Politics | World | Business | Analysis | Sport | Science | Health | Arts | Fact Check | 中文新闻 | Berita Bahasa Indonesia | Tok Pisin |
|
||||
| - | - | - | - | - | - | - | - | - | - | - | - | - | - |
|
||||
| justin | politics | world | business | analysis-and-opinion | sport | science | health | arts-culture | factcheck | chinese | indonesian | tok-pisin |
|
||||
|
||||
</Route>
|
||||
|
||||
## AP News
|
||||
|
||||
### Topics
|
||||
|
||||
@@ -10,6 +10,20 @@ pageClass: routes
|
||||
|
||||
<Route author="brilon" example="/21caijing/channel/readnumber" path="/21caijing/channel/:name" :paramsDesc="['频道名称,可在[https://m.21jingji.com/](https://m.21jingji.com/)页面URL中找到']"/>
|
||||
|
||||
## ABC News
|
||||
|
||||
### 子站
|
||||
|
||||
<Route author="nczitzk" example="/abc/chinese" path="/abc/:site?" :paramsDesc="['子站,见下表']">
|
||||
|
||||
子站
|
||||
|
||||
| Just In | Politics | World | Business | Analysis | Sport | Science | Health | Arts | Fact Check | 中文新闻 | Berita Bahasa Indonesia | Tok Pisin |
|
||||
| ------- | -------- | ----- | -------- | -------------------- | ----- | ------- | ------ | ------------ | ---------- | -------- | ----------------------- | --------- |
|
||||
| justin | politics | world | business | analysis-and-opinion | sport | science | health | arts-culture | factcheck | chinese | indonesian | tok-pisin |
|
||||
|
||||
</Route>
|
||||
|
||||
## AP News
|
||||
|
||||
### 话题
|
||||
|
||||
@@ -3260,6 +3260,9 @@ router.get('/appsales/:caty?/:time?', require('./routes/appsales/index'));
|
||||
// CGTN
|
||||
router.get('/cgtn/top', require('./routes/cgtn/top'));
|
||||
|
||||
// ABC News
|
||||
router.get('/abc/:site?', require('./routes/abc/index.js'));
|
||||
|
||||
// 台湾中央通讯社
|
||||
router.get('/cna/:id?', require('./routes/cna/index'));
|
||||
|
||||
|
||||
86
lib/routes/abc/index.js
Normal file
86
lib/routes/abc/index.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const url = require('url');
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
ctx.params.site = ctx.params.site || '';
|
||||
|
||||
const rootUrl = 'https://mobile.abc.net.au';
|
||||
const currentUrl = `${rootUrl}/news/${ctx.params.site}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
$('._3zQMR, .ticker').remove();
|
||||
|
||||
const list = $('h3')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: url.resolve(rootUrl, item.parents('a').attr('href') || item.find('a').attr('href')),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('.modal-content').remove();
|
||||
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', content(this).attr('data-src'));
|
||||
});
|
||||
|
||||
let coverImage, contentBody;
|
||||
if (content('div[data-component="FeatureMedia"]').html() !== null) {
|
||||
coverImage = content('div[data-component="FeatureMedia"]').html();
|
||||
} else {
|
||||
coverImage = content('.view-hero-media').html();
|
||||
}
|
||||
if (content('#body').html() !== null) {
|
||||
contentBody = content('#body').html();
|
||||
} else {
|
||||
contentBody = content('.article-text').html();
|
||||
}
|
||||
|
||||
const authorsArray = [];
|
||||
const authorsMatch = detailResponse.data.match(/author":(.*),"dateModified/);
|
||||
if (authorsMatch === null) {
|
||||
authorsArray.push(content('meta[name="DCTERMS.contributor"]').attr('content'));
|
||||
} else {
|
||||
const authors = JSON.parse(authorsMatch[1]);
|
||||
try {
|
||||
for (const author of authors) {
|
||||
authorsArray.push(author.name);
|
||||
}
|
||||
} catch (e) {
|
||||
authorsArray.push(authors.name);
|
||||
}
|
||||
}
|
||||
|
||||
item.description = coverImage + contentBody;
|
||||
item.pubDate = new Date(content('meta[property="article:published_time"]').attr('content')).toUTCString();
|
||||
item.author = authorsArray.join(', ');
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user