fix: 虎嗅搜索改版 (#3802)

This commit is contained in:
Henry Wang 2020-02-01 09:23:37 +00:00 committed by GitHub
parent f3a78c2c27
commit 514149aef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 10 deletions

View File

@ -1,25 +1,20 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
module.exports = async (ctx) => {
const { keyword } = ctx.params;
const link = `https://www.huxiu.com/search.html?s=${encodeURIComponent(keyword)}&sort=dateline:desc`;
const url = `https://search-api.huxiu.com/api/article?platform=www&s=${encodeURIComponent(keyword)}&sort=&page=1&pagesize=20`;
const link = 'https://www.huxiu.com';
const response = await got({
method: 'get',
url: link,
method: 'post',
url,
headers: {
Referer: link,
},
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('.search-wrap-list-ul > li > h2 > a')
.get()
.map((e) => $(e).attr('href'));
const list = response.data.data.datalist.slice(0, 10).map((d) => `${link}/article/${d.aid}.html`);
const items = await utils.ProcessFeed(list, ctx.cache);