mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-09 14:40:23 +08:00
feat: Add Google News (#3953)
This commit is contained in:
@@ -60,6 +60,10 @@ Support major channels, refer to [BBC RSS feeds](https://www.bbc.co.uk/news/1062
|
|||||||
|
|
||||||
</RouteEn>
|
</RouteEn>
|
||||||
|
|
||||||
|
## Google News
|
||||||
|
|
||||||
|
<Route author="zoenglinghou" example="/google/news/Headlines/hl=en-US&gl=US&ceid=US:en" path="/google/news/:category/:locale" :paramsDesc="['Category Title', 'locales, could be found behind `?`, including `hl`, `gl`, and `ceid` as parameters']"/>
|
||||||
|
|
||||||
## NHK
|
## NHK
|
||||||
|
|
||||||
### News Web Easy
|
### News Web Easy
|
||||||
@@ -128,12 +132,12 @@ Provides a better reading experience (full text articles) over the official one.
|
|||||||
|
|
||||||
`Region`
|
`Region`
|
||||||
| Hong Kong | Taiwan | US |
|
| Hong Kong | Taiwan | US |
|
||||||
| -- | -- | -- |
|
| --------- | ------ | --- |
|
||||||
| hk | tw | en |
|
| hk | tw | en |
|
||||||
|
|
||||||
`Category`
|
`Category`
|
||||||
| All | World | Business | Entertainment | Sports | Health |
|
| All | World | Business | Entertainment | Sports | Health |
|
||||||
| -- | -- | -- | -- | -- | -- |
|
| ------- | ----- | -------- | ------------- | ------ | ------ |
|
||||||
| (Empty) | world | business | entertainment | sports | health |
|
| (Empty) | world | business | entertainment | sports | health |
|
||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -104,12 +104,12 @@ Solidot 提供的 feed:
|
|||||||
|
|
||||||
`地区`
|
`地区`
|
||||||
| 香港 | 台灣 | 美國 |
|
| 香港 | 台灣 | 美國 |
|
||||||
| -- | -- | -- |
|
| ---- | ---- | ---- |
|
||||||
| hk | tw | en |
|
| hk | tw | en |
|
||||||
|
|
||||||
`类別`
|
`类別`
|
||||||
| 新聞總集 | 兩岸國際 | 財經 | 娛樂 | 體育 | 健康 |
|
| 新聞總集 | 兩岸國際 | 財經 | 娛樂 | 體育 | 健康 |
|
||||||
| -- | -- | -- | -- | -- | -- |
|
| -------- | -------- | -------- | ------------- | ------ | ------ |
|
||||||
| (空) | world | business | entertainment | sports | health |
|
| (空) | world | business | entertainment | sports | health |
|
||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
@@ -188,6 +188,10 @@ Category 列表:
|
|||||||
|
|
||||||
<Route author="HenryQW" example="/dwnews/rank" path="/dwnews/rank"/>
|
<Route author="HenryQW" example="/dwnews/rank" path="/dwnews/rank"/>
|
||||||
|
|
||||||
|
## 谷歌新闻
|
||||||
|
|
||||||
|
<Route author="zoenglinghou" example="/google/news/要闻/hl=zh-CN&gl=CN&ceid=CN:zh-Hans" path="/google/news/:category/:locale" :paramsDesc="['子分类标题', '地区语言设置,在地址栏 `?` 后,包含 `hl`,`gl`,以及 `ceid` 参数']"/>
|
||||||
|
|
||||||
## 华尔街见闻
|
## 华尔街见闻
|
||||||
|
|
||||||
### 华尔街见闻
|
### 华尔街见闻
|
||||||
|
|||||||
@@ -2228,4 +2228,7 @@ router.get('/cowlevel/element/:id', require('./routes/cowlevel/element'));
|
|||||||
// 2048
|
// 2048
|
||||||
router.get('/2048/bbs/:fid', require('./routes/2048/bbs'));
|
router.get('/2048/bbs/:fid', require('./routes/2048/bbs'));
|
||||||
|
|
||||||
|
// Google News
|
||||||
|
router.get('/google/news/:category/:locale', require('./routes/google/news'));
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
107
lib/routes/google/news.js
Normal file
107
lib/routes/google/news.js
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
const url = require('url');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const category = ctx.params.category;
|
||||||
|
const locale = ctx.params.locale;
|
||||||
|
|
||||||
|
const category_url = await ctx.cache.tryGet([locale, category], async () => {
|
||||||
|
const front_page = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: `https://news.google.com/?${locale}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
const front_data = front_page.data;
|
||||||
|
|
||||||
|
const $ = cheerio.load(front_data);
|
||||||
|
const category_list = $('a.wmzpFf.yETrXb');
|
||||||
|
|
||||||
|
const category_text = [];
|
||||||
|
category_list.each((index, item) => {
|
||||||
|
category_text.push($(item).text());
|
||||||
|
});
|
||||||
|
|
||||||
|
return url.resolve('https://news.google.com', category_list.eq(category_text.indexOf(category)).attr('href'));
|
||||||
|
});
|
||||||
|
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: category_url,
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = response.data;
|
||||||
|
const $ = cheerio.load(data);
|
||||||
|
const list = $('div.xrnccd');
|
||||||
|
|
||||||
|
let itemPicUrl;
|
||||||
|
let meta;
|
||||||
|
let description;
|
||||||
|
let link;
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title: $('title').text(),
|
||||||
|
link: category_url,
|
||||||
|
item:
|
||||||
|
list &&
|
||||||
|
list
|
||||||
|
.map((index, item) => {
|
||||||
|
item = $(item);
|
||||||
|
itemPicUrl = item.find('img').attr('src');
|
||||||
|
|
||||||
|
meta = item.find('div.SVJrMe').first();
|
||||||
|
|
||||||
|
description = item
|
||||||
|
.find('h4.ipQwMb')
|
||||||
|
.removeAttr('class')
|
||||||
|
.each((index, item) => {
|
||||||
|
$(item)
|
||||||
|
.children()
|
||||||
|
.removeAttr('class')
|
||||||
|
.attr(
|
||||||
|
'href',
|
||||||
|
url.resolve(
|
||||||
|
'https://news.google.com',
|
||||||
|
$(item)
|
||||||
|
.children()
|
||||||
|
.attr('href')
|
||||||
|
)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toString();
|
||||||
|
|
||||||
|
link = url.resolve(
|
||||||
|
'https://news.google.com',
|
||||||
|
item
|
||||||
|
.find('a.VDXfz')
|
||||||
|
.first()
|
||||||
|
.attr('href')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (itemPicUrl !== undefined) {
|
||||||
|
description = `${description}<img src="${itemPicUrl}">`;
|
||||||
|
}
|
||||||
|
if (description === null) {
|
||||||
|
description = link;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
title: item
|
||||||
|
.find('h3')
|
||||||
|
.children()
|
||||||
|
.text(),
|
||||||
|
description: description,
|
||||||
|
pubDate: meta
|
||||||
|
.find('time')
|
||||||
|
.first()
|
||||||
|
.attr('datetime'),
|
||||||
|
author: meta
|
||||||
|
.find('a.wEwyrc')
|
||||||
|
.first()
|
||||||
|
.text(),
|
||||||
|
link: link,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.get(),
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user