+16
-34
@@ -1,42 +1,24 @@
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
const axios = require('../../utils/axios');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const browser = await require('../../utils/puppeteer')();
|
||||
const page = await browser.newPage();
|
||||
|
||||
const link = 'https://sspai.com/series';
|
||||
|
||||
await page.goto(link);
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const html = await page.evaluate(() => document.querySelector('div.new-series-wrapper').innerHTML);
|
||||
browser.close();
|
||||
|
||||
const $ = cheerio.load(html);
|
||||
const list = $('div.item');
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: `https://sspai.com/api/v1/series/page/get?limit=5&sort=weight&offset=0&released_at=0`,
|
||||
headers: {
|
||||
Host: 'sspai.com',
|
||||
},
|
||||
});
|
||||
const data = response.data.data;
|
||||
|
||||
ctx.state.data = {
|
||||
title: '少数派 -- 最新上架付费专栏',
|
||||
link,
|
||||
link: 'https://sspai.com/series',
|
||||
description: '少数派 -- 最新上架付费专栏',
|
||||
item: list
|
||||
.map((i, item) => ({
|
||||
title: $(item)
|
||||
.find('.item-title a')
|
||||
.text()
|
||||
.trim(),
|
||||
link: url.resolve(
|
||||
link,
|
||||
$(item)
|
||||
.find('.item-title a')
|
||||
.attr('href')
|
||||
),
|
||||
author: $(item)
|
||||
.find('.item-author')
|
||||
.text()
|
||||
.trim(),
|
||||
}))
|
||||
.get(),
|
||||
item: data.map((item) => ({
|
||||
title: item.title,
|
||||
description: item.summary,
|
||||
link: `https://sspai.com/series/${item.id}`,
|
||||
author: item.nickname,
|
||||
})),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user