feat: router_japanpost (#4154)
This commit is contained in:
parent
1042d6bfb6
commit
cbc66c876f
|
|
@ -1405,4 +1405,17 @@
|
|||
},
|
||||
],
|
||||
},
|
||||
'japanpost.jp': {
|
||||
_name: '日本郵便',
|
||||
'trackings.post': [
|
||||
{
|
||||
title: '郵便・荷物の追跡',
|
||||
docs: 'https://docs.rsshub.app/other.html#ri-ben-you-bian',
|
||||
source: '/services/srv/search/direct',
|
||||
target: (params) => `/japanpost/${params.reqCode}/${params.locale}`,
|
||||
script: "({reqCode: new URLSearchParams(location.search).get('reqCodeNo1').toUpperCase(), locale: new URLSearchParams(location.search).get('locale').toLowerCase()})",
|
||||
verification: (params) => (params.reqCode.search(/^(?:\d{12}|[A-Z]{2}\d{9}[A-Z]{2})$/) === 0 && params.locale === 'ja') || params.locale === 'en',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -71,7 +71,13 @@ pageClass: routes
|
|||
|
||||
### Track & Trace Service
|
||||
|
||||
<RouteEn author="tuzi3040" example="/japanpost/EJ123456789JP" path="/japanpost/:reqCode" :paramsDesc="['Package Number']"/>
|
||||
<RouteEn author="tuzi3040" example="/japanpost/EJ123456789JP/en" path="/japanpost/:reqCode/:locale?" :paramsDesc="['Package Number', 'Language, default to japanese `ja`']" radar="1">
|
||||
|
||||
| Japanese | English |
|
||||
| -------- | ------- |
|
||||
| ja | en |
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Parcel Tracking
|
||||
|
||||
|
|
|
|||
|
|
@ -353,7 +353,13 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
### 郵便追跡サービス
|
||||
|
||||
<Route author="tuzi3040" example="/japanpost/EJ123456789JP" path="/japanpost/:reqCode" :paramsDesc="['运单号']"/>
|
||||
<Route author="tuzi3040" example="/japanpost/EJ123456789JP/ja" path="/japanpost/:reqCode/:locale?" :paramsDesc="['运单号', '语言,默认为`ja`']" radar="1">
|
||||
|
||||
| 日语 | 英语 |
|
||||
| ---- | ---- |
|
||||
| ja | en |
|
||||
|
||||
</Route>
|
||||
|
||||
## 上证债券信息网
|
||||
|
||||
|
|
|
|||
|
|
@ -1786,7 +1786,7 @@ router.get('/leboncoin/ad/:query', require('./routes/leboncoin/ad.js'));
|
|||
router.get('/dhl/:id', require('./routes/dhl/shipment-tracking'));
|
||||
|
||||
// Japanpost
|
||||
router.get('/japanpost/:reqCode', require('./routes/japanpost/index'));
|
||||
router.get('/japanpost/:reqCode/:locale?', require('./routes/japanpost/index'));
|
||||
|
||||
// 中华人民共和国商务部
|
||||
router.get('/mofcom/article/:suffix', require('./routes/mofcom/article'));
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ const cheerio = require('cheerio');
|
|||
const utils = require('./utils');
|
||||
|
||||
const baseTitle = '日本郵便';
|
||||
const baseUrl = 'https://trackings.post.japanpost.jp/services/srv/search/direct?locale=ja&reqCodeNo1=';
|
||||
const baseUrl = 'https://trackings.post.japanpost.jp/services/srv/search/direct?';
|
||||
|
||||
const util = new utils();
|
||||
util.expandEven();
|
||||
|
|
@ -11,7 +11,20 @@ util.expandReverse();
|
|||
|
||||
module.exports = async (ctx) => {
|
||||
const reqCode = ctx.params.reqCode;
|
||||
const link = baseUrl + reqCode;
|
||||
const reqReqCode = 'reqCodeNo1=' + reqCode;
|
||||
let locale;
|
||||
switch (ctx.params.locale) {
|
||||
case 'ja':
|
||||
locale = 'ja';
|
||||
break;
|
||||
case 'en':
|
||||
locale = 'en';
|
||||
break;
|
||||
default:
|
||||
locale = 'ja';
|
||||
}
|
||||
const reqLocale = '&locale=' + locale;
|
||||
const link = baseUrl + reqReqCode + reqLocale;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
|
|
@ -43,21 +56,19 @@ module.exports = async (ctx) => {
|
|||
.map((index, item) => {
|
||||
item = $(item);
|
||||
const itemTd = item.find('td');
|
||||
const itemTitle =
|
||||
itemTd
|
||||
.eq(1)
|
||||
.text()
|
||||
.trim() +
|
||||
' ' +
|
||||
itemTd
|
||||
.eq(4)
|
||||
.text()
|
||||
.trim() +
|
||||
' ' +
|
||||
itemTd
|
||||
.eq(3)
|
||||
.text()
|
||||
.trim();
|
||||
const packageStatus = itemTd
|
||||
.eq(1)
|
||||
.text()
|
||||
.trim();
|
||||
const packageRegion = itemTd
|
||||
.eq(4)
|
||||
.text()
|
||||
.trim();
|
||||
const packageOffice = itemTd
|
||||
.eq(3)
|
||||
.text()
|
||||
.trim();
|
||||
const itemTitle = `${packageStatus} ${packageRegion} ${packageOffice}`;
|
||||
const itemDescription = itemTd.eq(2).text();
|
||||
const itemPubDateText = itemTd.eq(0).text();
|
||||
const itemGuid = util.generateGuid(itemTitle + itemDescription + itemPubDateText);
|
||||
|
|
|
|||
Loading…
Reference in New Issue