feat: add telecompaper search (#6734)
This commit is contained in:
parent
f3e7f55c57
commit
e91d9968a1
|
|
@ -222,7 +222,7 @@ Solidot 提供的 feed:
|
|||
|
||||
### News
|
||||
|
||||
<Route author="nczitzk" example="/telecompaper/news/mobile/2020/China/News" path="/telecompaper/news/:caty/:year?/:country?/:type?/:keyword?" :paramsDesc="['分类,见下表', '年份,可在所选分类页中 Filter 的 `Years` 选择器中选择相应年份,不限年份则填入 `all`,默认为不限', '国家或大洲,可在所选分类页中 Filter 的 `Countries` 选择器中选择相应国家或大洲,不限国家或大洲则填入 `all`,默认为不限', '类型,可在所选分类页中 Filter 的 `Types` 选择器中选择相应类型,不限类型则填入 `all`,默认为不限', '搜索关键字']">
|
||||
<Route author="nczitzk" example="/telecompaper/news/mobile/2020/China/News" path="/telecompaper/news/:caty/:year?/:country?/:type?" :paramsDesc="['分类,见下表', '年份,可在所选分类页中 Filter 的 `Years` 选择器中选择相应年份,不限年份则填入 `all`,默认为不限', '国家或大洲,可在所选分类页中 Filter 的 `Countries` 选择器中选择相应国家或大洲,不限国家或大洲则填入 `all`,默认为不限', '类型,可在所选分类页中 Filter 的 `Types` 选择器中选择相应类型,不限类型则填入 `all`,默认为不限']">
|
||||
|
||||
可选分类如下
|
||||
|
||||
|
|
@ -240,6 +240,24 @@ Solidot 提供的 feed:
|
|||
|
||||
</Route>
|
||||
|
||||
### Search
|
||||
|
||||
<Route author="nczitzk" example="/telecompaper/search/Nokia" path="/telecompaper/search/:keyword?/:company?/:sort?/:period?" :paramsDesc="['关键词', '公司名,默认为不限', '排序,见下表,默认为 Date Descending', '发表在时间段内,默认为 12 months']">
|
||||
|
||||
排序
|
||||
|
||||
| Date Ascending | Date Descending |
|
||||
| -------------- | --------------- |
|
||||
| 1 | 2 |
|
||||
|
||||
发表在时间段内
|
||||
|
||||
| 1 month | 3 months | 6 months | 12 months | 24 months |
|
||||
| ------- | -------- | -------- | --------- | --------- |
|
||||
| 1 | 3 | 6 | 12 | 24 |
|
||||
|
||||
</Route>
|
||||
|
||||
## The Economist
|
||||
|
||||
### 分类
|
||||
|
|
|
|||
|
|
@ -3224,7 +3224,8 @@ router.get('/141ppv/:type/:key?', require('./routes/141ppv/141ppv'));
|
|||
router.get('/curiouscat/user/:id', require('./routes/curiouscat/user'));
|
||||
|
||||
// Telecompaper
|
||||
router.get('/telecompaper/news/:caty/:year?/:country?/:type?/:keyword?', require('./routes/telecompaper/news'));
|
||||
router.get('/telecompaper/news/:caty/:year?/:country?/:type?', require('./routes/telecompaper/news'));
|
||||
router.get('/telecompaper/search/:keyword?/:company?/:sort?/:period?', require('./routes/telecompaper/search'));
|
||||
|
||||
// 水木社区
|
||||
router.get('/newsmth/account/:id', require('./routes/newsmth/account'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const keyword = ctx.params.keyword || '';
|
||||
const company = ctx.params.company || '';
|
||||
const sort = ctx.params.sort || '2';
|
||||
const period = ctx.params.period || '12';
|
||||
|
||||
const rootUrl = `https://www.telecompaper.com/search/index.aspx?search=${keyword}`;
|
||||
|
||||
let response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
}),
|
||||
$ = cheerio.load(response.data);
|
||||
|
||||
response = await got({
|
||||
method: 'post',
|
||||
url: rootUrl,
|
||||
data: JSON.stringify({
|
||||
__EVENTTARGET: '',
|
||||
__EVENTARGUMENT: '',
|
||||
__VSTATE: $('#__VSTATE').attr('value'),
|
||||
__VIEWSTATE: '',
|
||||
ctl00$header$searchText: 'Search keywords',
|
||||
ctl00$header$searchTextMobile: 'Search keywords',
|
||||
ctl00$MainPlaceHolder$SearchText: keyword,
|
||||
ctl00$MainPlaceHolder$CompanyText: company,
|
||||
ctl00$MainPlaceHolder$Sort: parseInt(sort),
|
||||
ctl00$MainPlaceHolder$Results: 20,
|
||||
ctl00$MainPlaceHolder$Date: 'Timeframe1',
|
||||
ctl00$MainPlaceHolder$Period: parseInt(period),
|
||||
ctl00$MainPlaceHolder$txtStartDate: '',
|
||||
ctl00$MainPlaceHolder$txtEndDate: '',
|
||||
ctl00$MainPlaceHolder$chkEnglish: 'on',
|
||||
ctl00$MainPlaceHolder$Submit: 'Search',
|
||||
}),
|
||||
});
|
||||
$ = cheerio.load(response.data);
|
||||
|
||||
const list = $('table.details_rows tbody tr')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const a = item.find('a');
|
||||
return {
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
pubDate: new Date(item.find('span.source').text().split(' | ')[0] + ' GMT+1').toUTCString(),
|
||||
};
|
||||
})
|
||||
.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);
|
||||
|
||||
item.description = content('#pageContainer').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `Telecompaper Search - ${keyword}`,
|
||||
link: rootUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue