* 多抓鱼 搜索

* doc
This commit is contained in:
fengkx
2019-01-17 14:43:44 +08:00
committed by DIYgod
parent c42d6a26d0
commit f134fac915
3 changed files with 44 additions and 0 deletions

View File

@@ -2796,3 +2796,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
### 好奇心日报
<route name="最新" author="suprio" example="/qdaily" path="/qdaily/index" />
### 多抓鱼
<route name="搜索结果" author="fengkx" example="/duozhuayu/search/JavaScript" path="/duozhuayu/search/:wd" :paramsDesc="['搜索关键词']"/>

View File

@@ -970,4 +970,7 @@ router.get('/allpoetry/:order?', require('./routes/allpoetry/order'));
// 华尔街见闻
router.get('/wallstreetcn/news/global', require('./routes/wallstreetcn/news'));
// 多抓鱼搜索
router.get('/duozhuayu/search/:wd', require('./routes/duozhuayu/search'));
module.exports = router;

View File

@@ -0,0 +1,37 @@
const puppeteer = require('../../utils/puppeteer');
const cheerio = require('cheerio');
module.exports = async (ctx, next) => {
const wd = ctx.params.wd;
const link = `https://www.duozhuayu.com/search/${wd}`;
const browser = await puppeteer();
const page = await browser.newPage();
await page.goto(link, { waitUntil: 'networkidle0' });
// eslint-disable-next-line no-undef
const html = await page.evaluate(() => document.querySelector('html').innerHTML);
browser.close();
const $ = cheerio.load(html);
const books = $('.Search-section')
.eq(1)
.find('.SearchBookItem');
const item = books
.map((index, i) => {
const book = $(i);
const text = book.find('.SearchBookItem-title').text() + ' - ' + book.find('.SearchBookItem-description').text() + ' - ' + book.find('.Price').text();
return {
title: text,
link: `https://www.duozhuayu.com${book.attr('href')}`,
description: book.html(),
guid: `https://www.duozhuayu.com${book.attr('href')}${book.find('.Price').text()}`,
};
})
.get();
ctx.state.data = {
title: `多抓鱼搜索-${wd}`,
link,
description: `多抓鱼搜索-${wd}`,
item,
};
await next();
};