最近想看一下自己跑了多少高速,于是研究了一下苏通宝 ETC 的查询接口,发现他的查询接口比较简单:只需要提供 ETC 卡号和查询月份,就能获取对应月份的通行消费记录,根本不需要验证。
唯一需要绕一点的地方就是查询参数和返回参数都需要base64编码/解码了吧。
import requests
import base64
import json
import pandas as pd
url = "https://qrcode.jstxb.com/WebsiteAdmin/admin/ApiIndex"
card_id = "你想查询的卡号"
data = []
for year in range(2024, 2027):
for month in range(1, 13):
# 超过查询范围后停止,这里我查询到202609
if year == 2026 and month == 10:
break
p = f"{year}{month:02d}"
# 构造请求参数
query = {
"fun": "Website/Card/getTranRecord",
"data": {
"month": p,
"cardId": card_id,
"type": ""
}
}
# JSON → Base64
query = json.dumps(
query,
ensure_ascii=False,
separators=(",", ":")
)
encoded = base64.b64encode(
query.encode("utf-8")
).decode("utf-8")
# 发送请求
r = requests.post(url, data=encoded)
# Base64 → JSON
result = json.loads(
base64.b64decode(r.text).decode("utf-8")
)
# 保存查询结果
data.extend(result.get("data", []))
print(p, "获取", len(result.get("data", [])), "条")
# 转换为 Excel
df = pd.DataFrame(data)
df.to_excel(
"苏通宝ETC通行记录.xlsx",
index=False
)
print("完成,共获取", len(df), "条记录")
| cardId | passId | enStationName | exStationName | enDateTime | exDateTime | fee |
|---|---|---|---|---|---|---|
| 240123... | 013201... | 南京某收费站 | 苏州某收费站 | 2026-09-06 08:42:05 | 2026-09-06 09:39:53 | 5206 |
| 240123... | 013201... | 苏州某收费站 | 南京某收费站 | 2026-09-06 16:05:57 | 2026-09-06 17:09:26 | 5206 |
结果类似上面这样,fee是人民币分,除以100就是人民币元了,可惜看不到里程数,还是没达到我的预期。



Comments | NOTHING