mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix: 36kr search error (#2472)
* fix: 36kr search * fix: 36kr search error
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ pageClass: routes
|
||||
|
||||
### 搜索文章
|
||||
|
||||
<Route author="xyqfer" example="/36kr/search/article/8%E7%82%B91%E6%B0%AA" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
|
||||
<Route author="xyqfer kt286" example="/36kr/search/article/ofo" path="/36kr/search/article/:keyword" :paramsDesc="['关键字']" />
|
||||
|
||||
## 99% Invisible
|
||||
|
||||
|
||||
@@ -2,9 +2,27 @@ const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { keyword = '' } = ctx.params;
|
||||
const csrfresponse = await got.get('https://36kr.com/pp/api/csrf');
|
||||
const cookies = csrfresponse.headers['set-cookie'].toString();
|
||||
const token = cookies.match(/M-XSRF-TOKEN=.{64}/)[0];
|
||||
const acw_tc = cookies.match(/acw_tc=.{61}/)[0];
|
||||
const krnewsfrontss = cookies.match(/krnewsfrontss=.{32}/)[0];
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://36kr.com/pp/api/search/entity-search?page=1&per_page=20&sort=date&entity_type=post&keyword=${encodeURIComponent(keyword)}`,
|
||||
method: 'post',
|
||||
url: `https://36kr.com/pp/api/search/entity-search`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
cookie: `${token};${acw_tc};${krnewsfrontss};`,
|
||||
'M-X-XSRF-TOKEN': token.replace('M-XSRF-TOKEN=', ''),
|
||||
},
|
||||
data: JSON.stringify({
|
||||
page: 1,
|
||||
per_page: 20,
|
||||
sort: 'date',
|
||||
entity_type: 'post',
|
||||
keyword: encodeURIComponent(keyword),
|
||||
}),
|
||||
});
|
||||
|
||||
const load = async (link) => {
|
||||
@@ -12,8 +30,9 @@ module.exports = async (ctx) => {
|
||||
const description = response.data.data.content;
|
||||
return { description };
|
||||
};
|
||||
|
||||
const items = await Promise.all(
|
||||
response.data.data.items.map(async (item) => {
|
||||
(response.data.data.items || []).map(async (item) => {
|
||||
const link = `https://36kr.com/api/post/${item.id}`;
|
||||
const single = {
|
||||
title: item.title,
|
||||
|
||||
Reference in New Issue
Block a user