feat(route): add 京东商品价格 (#9629)
This commit is contained in:
parent
3073ef2e58
commit
3b73533f95
|
|
@ -171,6 +171,20 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
|
|||
|
||||
<Route author="hoilc" example="/haohaozhu/discover/厨房" path="/haohaozhu/discover/:keyword?" :paramsDesc="['分类名或关键字,请使用中文']"/>
|
||||
|
||||
## 京东
|
||||
|
||||
### 商品价格
|
||||
|
||||
<Route author="nczitzk" example="/jd/price/526835" path="/jd/price/:id" :paramsDesc="['商品 id,可在商品详情页 URL 中找到']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
如商品 <https://item.jd.com/526835.html> 中的 id 为 `526835`,所以路由为 [`/jd/price/526835`](https://rsshub.app/jd/price/526835)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 京东众筹
|
||||
|
||||
### 众筹项目
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/price/:id': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
const got = require('@/utils/got');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const rootUrl = 'https://item.jd.com';
|
||||
const currentUrl = `${rootUrl}/${id}.html`;
|
||||
const apiUrl = `http://p.3.cn/prices/mgets?skuIds=J_${id}`;
|
||||
|
||||
const apiResponse = await got({
|
||||
method: 'get',
|
||||
url: apiUrl,
|
||||
});
|
||||
|
||||
const data = apiResponse.data[0];
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const title = response.data.match(/name: '(.*?)'/)[1];
|
||||
|
||||
ctx.state.data = {
|
||||
title: `京东商品价格 - ${title}`,
|
||||
link: currentUrl,
|
||||
item: [
|
||||
{
|
||||
title,
|
||||
link: currentUrl,
|
||||
description: art(path.join(__dirname, 'templates/description.art'), {
|
||||
p: data.p,
|
||||
op: data.op,
|
||||
m: data.m,
|
||||
}),
|
||||
},
|
||||
],
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'jd.com': {
|
||||
_name: '京东',
|
||||
item: [
|
||||
{
|
||||
title: '商品价格',
|
||||
docs: 'https://docs.rsshub.app/shopping.html#jing-dong-shang-pin-jia-ge',
|
||||
source: ['/'],
|
||||
target: (params, url) => `/jd/price/${new URL(url).hash.match(/\/(\d+)\.html/)[1]}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/price/:id', require('./price'));
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<p>目前价格:<b>{{ p }}</b></p>
|
||||
<p>指导价:<b>{{ op }}</b></p>
|
||||
<p>最高价:<b>{{ m }}</b></p>
|
||||
Loading…
Reference in New Issue