diff --git a/lib/config.js b/lib/config.js index 317b316f1..2acce777a 100644 --- a/lib/config.js +++ b/lib/config.js @@ -275,6 +275,9 @@ const calculateValue = () => { telegram: { token: envs.TELEGRAM_TOKEN, }, + tophub: { + cookie: envs.TOPHUB_COOKIE, + }, twitter: { consumer_key: envs.TWITTER_CONSUMER_KEY, consumer_secret: envs.TWITTER_CONSUMER_SECRET, diff --git a/lib/routes/tophub/index.js b/lib/routes/tophub/index.js index 114703b99..68d61d8e7 100644 --- a/lib/routes/tophub/index.js +++ b/lib/routes/tophub/index.js @@ -1,11 +1,17 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const config = require('@/config').value; module.exports = async (ctx) => { const id = ctx.params.id; const link = `https://tophub.today/n/${id}`; - const response = await got.get(link); + const response = await got.get(link, { + headers: { + Referer: 'https://tophub.today', + Cookie: config.tophub.cookie, + }, + }); const $ = cheerio.load(response.data); const title = $('div.Xc-ec-L.b-L').text().trim(); diff --git a/website/docs/routes/new-media.md b/website/docs/routes/new-media.md index 9cb6d62bd..6f7f021e8 100644 --- a/website/docs/routes/new-media.md +++ b/website/docs/routes/new-media.md @@ -3053,6 +3053,12 @@ others = 热点新闻 + 滚动新闻 ## 今日热榜 {#jin-ri-re-bang} +:::caution + +由于需要登录后的 Cookie 值才能获取原始链接,所以需要自建,需要在环境变量中配置 `TOPHUB_COOKIE`,详情见部署页面的配置模块。 + +::: + ### 榜单 {#jin-ri-re-bang-bang-dan} diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/install/README.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/install/README.md index a883e9adb..be71f2aa5 100644 --- a/website/i18n/zh/docusaurus-plugin-content-docs/current/install/README.md +++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/install/README.md @@ -977,6 +977,10 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行 - `HEFENG_KEY`:API key +- 今日热榜 + + - `TOPHUB_COOKIE`: 今日热榜登录后的 cookie,目前只需要 `itc_center_user=...` 以获取原始链接 + - 南方周末付费全文 - `INFZM_COOKIE`: infzm 账户登陆后的 cookie,目前只需要 `passport_session=...` 即可获取全文