#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""check_yingquan_list.py —— 列表对账：容器内标记数 vs parse_list 输出数"""
import importlib.util
import re

spec = importlib.util.spec_from_file_location("m", "/root/gov_crawler/crawl_yingquan_gggs.py")
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)

h = m.fetch(m.LIST_URL)
print("页面字节:", len(h))

box = h[h.find("m-cglist"):]
box = box[:box.find("pagination")] if "pagination" in box else box
li_n = len(re.findall(r"<li", box, re.I))
mark_n = len(re.findall(r"<span>\s*20\d\d-\d{1,2}-\d{1,2}\s*</span>", box))
print("容器内 <li>:", li_n)
print("容器内「<span>日期</span>」标记:", mark_n)

its = m.parse_list(h)
print("parse_list 输出:", len(its))
for u, t, d in its[:4]:
    print("   ", d, "|", t[:42], "|", u[-26:])
print("对账:", "✅ 一致" if len(its) == mark_n else "❌ 差 %d" % (mark_n - len(its)))

# 全局 vs 容器内对比：确认没有把侧栏/他栏目混进来
allmarks = len(re.findall(r"<span>\s*20\d\d-\d{1,2}-\d{1,2}\s*</span>", h))
print("全页 <span>日期</span> 总数:", allmarks, "（与容器内相同 → 无其他带日期的栏目块）")
