Files
RSSHub/lib/v2/qianzhan/rank.js
mokevip8 2c3fa64035 feat(route): 增加前瞻网 (#10524)
* 增加前瞻网

* style: auto format

* chore(deps): bump rand-user-agent from 1.0.77 to 1.0.79 (#137)

Bumps [rand-user-agent](https://github.com/WebScrapingAPI/rand-user-agent) from 1.0.77 to 1.0.79.
- [Release notes](https://github.com/WebScrapingAPI/rand-user-agent/releases)
- [Commits](https://github.com/WebScrapingAPI/rand-user-agent/commits)

---
updated-dependencies:
- dependency-name: rand-user-agent
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: apply suggestions from cr

* fix: deepscan warning

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-07 02:31:05 +05:00

41 lines
1.5 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const type = ctx.params.type === 'week' ? 1 : 2;
const rootUrl = 'https://www.qianzhan.com/analyst/';
const response = await got(rootUrl);
const $ = cheerio.load(response.data);
const links = $(`#div_hotlist ul[idx='${type}'] a`).map((_, item) => $(item).attr('href'));
const items = await Promise.all(
links.map((_, item) =>
ctx.cache.tryGet(item, async () => {
const detailResponse = await got(item);
const $ = cheerio.load(detailResponse.data);
const description = $('#divArtBody').html();
const title = $('#h_title').text();
const pubDate = timezone(parseDate($('#pubtime_baidu').text().split('• ')[1], 'YYYY-MM-DD HH:mm:ss'), +8);
const author = $('.bljjxue').text().match(/\S+/)[0];
return {
title,
link: item,
description,
pubDate,
author,
category: $('meta[name="Keywords"]').attr('content').split(','),
};
})
)
);
ctx.state.data = {
title: `前瞻经济学人 - ${type === 1 ? '周排行' : '月排行'}`,
link: rootUrl,
item: items,
};
};