Files
RSSHub/lib/routes/wineyun/index.js
T
Sukka d82847f541 style/chore(eslint): enforce new rules (#8040)
* style: prefer object shorthand syntax
* refactor: prefer Array#map over Array#forEach
* style: prefer arrow callback
* chore(eslint): update rules
* style: auto fix by eslint
2021-08-17 22:23:23 +08:00

37 lines
1020 B
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const JSON5 = require('json5');
module.exports = async (ctx) => {
const category = ctx.params.category;
const url = 'http://www.wineyun.com/' + category;
const response = await got({
method: 'get',
url,
headers: {
Referer: 'http://www.wineyun.com',
},
});
const $ = cheerio.load(response.data);
const description = $('head title');
const regex = /new Vue\({\s+el: '#wy_app',[\s\S]+data: {[\s\S]+list: (.+),/gm;
const match = regex.exec(response.data);
const list = JSON5.parse(match[1]);
const resultItem = list.map((item) => ({
title: `¥${item.price} ${item.goodsname}`,
link: `http://www.wineyun.com/group/${item.id}`,
description: `<img src ="${item.Image}"><br>${item.summary}`,
}));
ctx.state.data = {
title: '酒云网-最新商品',
link: url,
item: resultItem,
description,
};
};