42 lines
2.0 KiB
Python
42 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""快速判定“无导出入口”报表页的真实结构:等待15s后统计 #icon-download / 文字下载按钮 / 是否需先查询。"""
|
||
|
|
import json, urllib.request, time
|
||
|
|
D = "http://127.0.0.1:10086/command"; S = "2haohr"
|
||
|
|
def call(a, args, t=90):
|
||
|
|
b = json.dumps({"action": a, "args": args, "session": S}).encode()
|
||
|
|
r = urllib.request.Request(D, data=b, headers={"Content-Type": "application/json"})
|
||
|
|
return json.loads(urllib.request.urlopen(r, timeout=t).read().decode())
|
||
|
|
def ev(c):
|
||
|
|
try: return call("evaluate", {"code": c}).get("data", {}).get("value")
|
||
|
|
except Exception as e: return "EXC:" + str(e)[:80]
|
||
|
|
|
||
|
|
STAT = r"""(()=>{
|
||
|
|
let icon=0;document.querySelectorAll('use').forEach(u=>{const h=u.getAttribute('xlink:href')||u.getAttribute('href');if(h==='#icon-download')icon++;});
|
||
|
|
const btns=[...document.querySelectorAll('button,a,[role=button]')].map(b=>(b.innerText||'').trim()).filter(t=>t&&t.length<12&&/下载|导出|生成|查询|搜索|excel/i.test(t));
|
||
|
|
const bcnt={};btns.forEach(t=>bcnt[t]=(bcnt[t]||0)+1);
|
||
|
|
// 是否存在数据表格
|
||
|
|
const tbl=document.querySelectorAll('table,[class*=table],[class*=Table]').length;
|
||
|
|
const empty=/暂无数据|请选择|请先|no data/i.test(document.body.innerText||'');
|
||
|
|
return JSON.stringify({icon_download:icon,dl_btns:bcnt,tables:tbl,has_empty_hint:empty});})()"""
|
||
|
|
|
||
|
|
def probe(url, label):
|
||
|
|
call("navigate", {"url": url, "newTab": False})
|
||
|
|
time.sleep(15)
|
||
|
|
print("[%s] %s" % (label, url))
|
||
|
|
print(" ", ev(STAT))
|
||
|
|
|
||
|
|
def main():
|
||
|
|
call("find_tab", {"url": "2haohr.com"})
|
||
|
|
for url, label in [
|
||
|
|
("https://2haohr.com/attendance/stat/monthly", "月考勤表"),
|
||
|
|
("https://2haohr.com/attendance/stat/report", "考勤报表"),
|
||
|
|
("https://2haohr.com/social-insurance/reports", "社保报表"),
|
||
|
|
("https://2haohr.com/org/org-forms", "组织报表"),
|
||
|
|
("https://2haohr.com/payroll/salary/report", "薪酬报表"),
|
||
|
|
]:
|
||
|
|
probe(url, label)
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|