Added Pincong

This commit is contained in:
zph 2020-12-30 21:17:29 +08:00
parent b1ae777b87
commit 27477a37e0
5 changed files with 128 additions and 0 deletions

View File

@ -395,6 +395,24 @@ pageClass: routes
</Route>
## 品葱
### 发现
<Route author="zphw" example="/pincong/category/1/new" path="/pincong/category/:category?/:sort?" :paramsDesc="['分类,与官网分类 URL `category-` 后的数字对应,默认为全部', '排序方式,参数可见下表,默认为推荐']" anticrawler="1" />
| 最新 | 推荐 | 热门 |
| ---- | --------- | ---- |
| new | recommend | hot |
### 精选
<Route author="zphw" example="/pincong/hot" path="/pincong/hot/:category?" :paramsDesc="['分类,与官网分类 URL `category-` 后的数字对应,默认为全部']" anticrawler="1" />
### 话题
<Route author="zphw" example="/pincong/topic/美国" path="/pincong/topic/:topic?" :paramsDesc="['话题,可在官网获取']" anticrawler="1" />
## 三星盖乐世社区
### 最新帖子

View File

@ -3780,4 +3780,9 @@ router.get('/nace/blog/:sort?', require('./routes/nace/blog'));
// Caixin Latest
router.get('/caixin/latest', require('./routes/caixin/latest'));
// Pincong 品葱
router.get('/pincong/category/:category?/:sort?', require('./routes/pincong/index'));
router.get('/pincong/hot/:category?', require('./routes/pincong/hot'));
router.get('/pincong/topic/:topic', require('./routes/pincong/topic'));
module.exports = router;

33
lib/routes/pincong/hot.js Normal file
View File

@ -0,0 +1,33 @@
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let url = 'https://pincong.rocks/hot/list/';
url += ctx.params.category ? 'category-' + ctx.params.category : 'category-0';
// use Puppeteer due to the obstacle by cloudflare challenge
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.goto(url);
const html = await page.evaluate(
// eslint-disable-next-line no-undef
() => document.documentElement.innerHTML
);
browser.close();
const $ = cheerio.load(html);
const list = $('div.aw-item');
ctx.state.data = {
title: '品葱 - 精选',
link: 'https://pincong.rocks/hot/',
item: list
.map((_, item) => ({
title: $(item).find('h2 a').text().trim(),
description: $(item).find('div.markitup-box').html(),
link: 'https://pincong.rocks' + $(item).find('div.mod-head h2 a').attr('href'),
}))
.get(),
};
};

View File

@ -0,0 +1,40 @@
const cheerio = require('cheerio');
module.exports = async (ctx) => {
let url = 'https://pincong.rocks/';
const sortMap = {
new: 'sort_type-new',
recommend: 'recommend-1',
hot: 'sort_type-hot__day2',
};
url += (ctx.params.sort && sortMap[ctx.params.sort]) || 'recommend-1';
url += ctx.params.category ? '__category-' + ctx.params.category : '';
// use Puppeteer due to the obstacle by cloudflare challenge
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.goto(url);
const html = await page.evaluate(
// eslint-disable-next-line no-undef
() => document.querySelector('div.aw-common-list').innerHTML
);
browser.close();
const $ = cheerio.load(html);
const list = $('div.aw-item');
ctx.state.data = {
title: '品葱 - 发现',
link: url,
item: list
.map((_, item) => ({
title: $(item).find('h4 a').text().trim(),
link: 'https://pincong.rocks' + $(item).find('h4 a').attr('href'),
pubDate: new Date($(item).attr('data-timestamp') * 1000).toISOString(),
}))
.get(),
};
};

View File

@ -0,0 +1,32 @@
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'https://pincong.rocks/topic/' + ctx.params.topic;
// use Puppeteer due to the obstacle by cloudflare challenge
const browser = await require('@/utils/puppeteer')();
const page = await browser.newPage();
await page.goto(url);
const html = await page.evaluate(
() =>
// eslint-disable-next-line no-undef
(document.querySelector('div.aw-common-list') && document.querySelector('div.aw-common-list').innerHTML) || ''
);
browser.close();
const $ = cheerio.load(html);
const list = $('div.aw-item');
ctx.state.data = {
title: `品葱 - ${ctx.params.topic}`,
link: url,
item: list
.map((_, item) => ({
title: $(item).find('h4 a').text().trim(),
link: 'https://pincong.rocks' + $(item).find('h4 a').attr('href'),
pubDate: new Date($(item).attr('data-timestamp') * 1000).toISOString(),
}))
.get(),
};
};