Skip to content

Commit

Permalink
Support fulltext acquirement in infzm (DIYgod#8590)
Browse files Browse the repository at this point in the history
  • Loading branch information
peng1999 authored Nov 27, 2021
1 parent 5e88989 commit 0230a94
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
3 changes: 3 additions & 0 deletions docs/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,6 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- `EH_IPB_MEMBER_ID`: E-Hentai 账户登录后 cookie 的 `ipb_member_id`
- `EH_IPB_PASS_HASH`: E-Hentai 账户登录后 cookie 的 `ipb_pass_hash`
- `EH_SK`: E-Hentai 账户登录后 cookie 中的`sk`

- 南方周末付费全文
- `INFZM_COOKIE`: infzm 账户登陆后的 cookie,目前只需要 `passport_session=...` 即可获取全文
3 changes: 3 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ const calculateValue = () => {
ipb_pass_hash: envs.EH_IPB_PASS_HASH,
sk: envs.EH_SK,
},
infzm: {
cookie: envs.INFZM_COOKIE,
},
};
};
calculateValue();
Expand Down
26 changes: 9 additions & 17 deletions lib/routes/infzm/news.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const config = require('@/config').value;
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const cheerio = require('cheerio');
Expand Down Expand Up @@ -28,26 +29,17 @@ module.exports = async (ctx) => {
if (value) {
description = value;
} else {
const cookie = config.infzm.cookie;
const response = await got({
method: 'get',
url: `http://api.infzm.com/mobile/contents/${id}`,
url: `http://www.infzm.com/content/${id}`,
headers: {
Referer: link,
Cookie: cookie || `passport_session=${Math.floor(Math.random() * 100)};`,
},
});

if (response.data.code === 200) {
description = response.data.data.content.fulltext;
} else {
// 有时候接口会返回未发布但实际已发布
const response = await got({
method: 'get',
url: `http://www.infzm.com/content/${id}`,
headers: {
Referer: link,
Cookie: `PHPSESSID=${Math.floor(Math.random() * 100)};`,
},
});
const $ = cheerio.load(response.data);
description = $('#content').html();
}
const $ = cheerio.load(response.data);
description = $('div.nfzm-content__content').html();

ctx.cache.set(key, description);
}
Expand Down

0 comments on commit 0230a94

Please sign in to comment.