feat: 新增交通银行数据导出插件及测试通道机制
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""页面状态观察探针:不点任何按钮,只每秒抓一次交易流水页的关键状态并落盘。
|
||||
|
||||
用途:人工自己填日期 / 点「查询」,脚本记录「查询前 → 查询后」的状态差异,
|
||||
用于确定「有无数据」的判定标志(暂无数据 / 表格行数 / 分页条数)。
|
||||
|
||||
用法:.venv\\Scripts\\python.exe tests\\bankcomm_probe\\page_state_watch.py [秒数]
|
||||
输出:logs/bankcomm_probe/watch_state.log(状态变化时才写一行)
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
from DrissionPage import ChromiumPage
|
||||
|
||||
REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
LOG = os.path.join(REPO, 'logs', 'bankcomm_probe', 'watch_state.log')
|
||||
LIFE = int(sys.argv[1]) if len(sys.argv) > 1 else 1800
|
||||
|
||||
SNAP = r"""
|
||||
var p = document.querySelector('.ant-calendar-picker-container');
|
||||
var tbody = document.querySelectorAll('.ant-table-tbody tr');
|
||||
var rows = 0;
|
||||
for (var i = 0; i < tbody.length; i++) {
|
||||
if (!tbody[i].classList.contains('ant-table-placeholder')) rows++;
|
||||
}
|
||||
function txt(sel) { var e = document.querySelector(sel); return e ? (e.innerText || '').replace(/\s+/g, ' ').trim().slice(0, 160) : ''; }
|
||||
return JSON.stringify({
|
||||
url: location.href,
|
||||
t: new Date().toTimeString().slice(0, 8),
|
||||
dates: [].slice.call(document.querySelectorAll('input.ant-calendar-picker-input'))
|
||||
.filter(function(e){return e.offsetWidth>0;}).map(function(e){return e.value;}),
|
||||
sels: [].slice.call(document.querySelectorAll('.ant-select-selection__rendered'))
|
||||
.map(function(e){return (e.innerText||'').replace(/\s+/g,' ').trim();}).slice(0, 12),
|
||||
rows: rows,
|
||||
placeholder: !!document.querySelector('.ant-table-placeholder'),
|
||||
emptyText: (document.body.innerText || '').indexOf('暂无数据') >= 0,
|
||||
spin: document.querySelectorAll('.ant-spin-spinning').length,
|
||||
pager: txt('.ant-pagination'),
|
||||
total: txt('.ant-table-footer') || txt('.ant-pagination-total-text'),
|
||||
msg: txt('.ant-message'),
|
||||
panelOpen: !!(p && p.offsetWidth > 0)
|
||||
});
|
||||
"""
|
||||
|
||||
page = ChromiumPage('127.0.0.1:9333')
|
||||
os.makedirs(os.path.dirname(LOG), exist_ok=True)
|
||||
fh = open(LOG, 'w', encoding='utf-8', buffering=1)
|
||||
start = time.time()
|
||||
last = None
|
||||
print(f'观察中,日志:{LOG}', flush=True)
|
||||
|
||||
while time.time() - start < LIFE:
|
||||
try:
|
||||
raw = page.run_js(SNAP)
|
||||
except Exception as e:
|
||||
print(f'页面已关闭或异常:{e}', flush=True)
|
||||
break
|
||||
if not raw:
|
||||
time.sleep(1)
|
||||
continue
|
||||
try:
|
||||
d = json.loads(raw)
|
||||
except Exception:
|
||||
time.sleep(1)
|
||||
continue
|
||||
key = json.dumps({k: v for k, v in d.items() if k != 't'}, ensure_ascii=False, sort_keys=True)
|
||||
if key != last:
|
||||
last = key
|
||||
line = time.strftime('%H:%M:%S') + ' ' + json.dumps(
|
||||
{k: v for k, v in d.items() if k != 't'}, ensure_ascii=False)
|
||||
fh.write(line + '\n')
|
||||
print(line, flush=True)
|
||||
time.sleep(1)
|
||||
|
||||
fh.close()
|
||||
print('观察结束', flush=True)
|
||||
Reference in New Issue
Block a user