【AirScript脚本】批量查询快递信息 (支持国际和国内运单号)
请使用 WPS AI 版本
使用17Track提供的api接口查询,每月100免费额度,可以多申请几个账号白嫖额度
可以自定义代码中Application.Range("单元格").Text 和 Application.Range("单元格").Value单元格的名称,来实现 输入 输出 单元格位置的更改
因为WPS限制运行脚本时调用网络接口的次数,所以有一个查询进度,以便于待查询单号过多时一次查不完
配合WPS中的功能 定时任务 使用效果更佳
如果有其他问题请在评论区留言
预览图
定位关键字为 开启追踪 请在其他单元格避免使用该关键字
BF2 暂存查询进度
C2 查询数量
Q1 填写17track Token
U1 显示剩余追踪数量
关键字 开启追踪 所在列 S 是第19列
故 变量 j = 19
BE列判断单号是否已上传17Track
初始值请手动填写 未上传
脚本上传单号后会自动更新为 已上传
脚本测试
请使用WPS-AI版本创建智能表格
找到脚本编辑器粘贴脚本
添加网络API服务
在未改动脚本的情况下
最少需要填写的测试参数请参考下图
Q2为我的17Track key 仅用来作为测试使用!
也可以自己注册换成自己的key
第一次执行脚本后
BF2变为 110
BE3变为已上传
U1新增剩余单数
第二次执行脚本前请把BF2还原为1
第二次执行脚本后即可看到追踪信息
由于程序执行和表格覆写速度限制,未提交单号的情况下第一次执行程序只能做提交单号一个动作,第二次执行程序才会开始查询
已提交单号后,执行程序会跳过提交单号步骤直接开始查询
脚本可以复制出来点击即可运行不用每次都到脚本编辑页面点击运行
代码
let now = Application.Range("BF2").Text
//进度保存
let end = Application.Range("C2").Text
//待查询单号数量
const token = Application.Range("Q1").Text
// 17track Token
const sleeptime = 1000
//时延
let j =19
//单号所在列数
const usedRange = Application.ActiveSheet.UsedRange
now = Number(now)
end = Number(end)+100
// 加100行防止查询不到
for (let i = now ; i <= end; i++) {
const row = Application.ActiveSheet.Rows(i)
const rg = row.Columns(j)
const rgr1 = row.Columns(j+1)
const rgr2 = row.Columns(j+2)
const rgl3 = row.Columns(j-1)
const rgr38 = row.Columns(j+38)
const text = rg.Text
const textl3 = rgl3.Text
let textr38 = rgr38.Text
let textr1 = rgr1.Text
var str = text
var strr38 = textr38
console.log(rgl3.Text)
console.log(rgr1.Text)
if (str.match("开启追踪") && strr38.match("未上传"))
{
let data = '[{"number":"'+ textl3 + '"}]'
console.log(data)
let respup = HTTP.fetch('https://api.17track.net/track/v2/register',
{
method:"POST",
timeout:2000,
headers:{
'content-type': 'application/json',
'17token': token
},
body:data
})
textr38 = respup.text()
console.log(textr38)
if (textr38.match("accepted")||textr38.match("-18019901"))
{rgr38.Value = "已上传"}
else {rg.Value = "上传失败"}
Time.sleep(sleeptime)
let resquota = HTTP.fetch('https://api.17track.net/track/v2/getquota',
{
method:"POST",
timeout:2000,
headers:{
'content-type': 'application/json',
'17token': token
},
body:'[]'
})
let dataquota1 = resquota.text()
let dataquota2 = dataquota1
console.log(dataquota1)
let c1 = dataquota1.search('quota_total')
dataquota1 = dataquota1.slice(c1+13)
let c2 = dataquota1.search(',"')
dataquota1 = dataquota1.slice(0,c2)
let c3 = dataquota2.search('quota_remain')
dataquota2 = dataquota2.slice(c3+14)
let c4 = dataquota2.search(',"')
dataquota2 = dataquota2.slice(0,c4)
Application.Range("U1").Value = '['+dataquota2 + '/' + dataquota1 + ']'
Time.sleep(sleeptime)
}
else {
}
if (str.match("开启追踪") && strr38.match("已上传") && textr1 != "成功签收" )
{
let resp = HTTP.fetch('https://api.17track.net/track/v2/gettrackinfo',{
method:"POST",
timeout:2000,
headers:{
'content-type': 'application/json',
'17token': token
},
body:'[{"number":"'+ textl3 +'"}]'
})
var textdata1 = resp.text()
var textdata2 = textdata1
if(textdata1.match("-18019902")){rgr1.Value="未注册"}
{
let a1 = textdata1.search('"latest_status"')
textdata1 = textdata1.slice(a1)
let a2 = textdata1.search('},')
textdata1 = textdata1.slice(0,a2)
let a3 = textdata1.search('"status":"')
textdata1 = textdata1.slice(a3+10)
let a4 = textdata1.search('"')
textdata1 = textdata1.slice(0,a4)
if(textdata1 == "NotFound"){rgr1.Value = "查询不到"}
else{if(textdata1 == "InfoReceived"){rgr1.Value = "收到信息"}
else{if(textdata1 == "InTransit"){rgr1.Value = "包裹在途"}
else{if(textdata1 == "Expired"){rgr1.Value = "运输过久"}
else{if(textdata1 == "AvailableForPickup"){rgr1.Value = "到达待取"}
else{if(textdata1 == "OutForDelivery"){rgr1.Value = "正在派件"}
else{if(textdata1 == "DeliveryFailure"){rgr1.Value = "投递失败"}
else{if(textdata1 == "Delivered"){rgr1.Value = "成功签收"}
else{if(textdata1 == "Exception"){rgr1.Value = "可能异常"}
}}}}}}}}
let b1 = textdata2.search('latest_even')
textdata2 = textdata2.slice(b1)
let b2 = textdata2.search('},')
textdata2 = textdata2.slice(0,b2)
let b3 = textdata2.search('time_iso')
let timeiso = textdata2.slice(b3+16,b3+21)
let b4 = textdata2.search('description')
textdata2 = textdata2.slice(b4+14)
let b5 = textdata2.search('"')
textdata2 = textdata2.slice(0,b5)
rgr2.Value = timeiso + " " + textdata2
Time.sleep(sleeptime)
}
}
Application.Range("BF2").Value = i
}

