#!/usr/bin/env python3
"""Quick test - run first 2 pages of each column in crawl_jxlc_v2."""
import sys, os
# Modify COLUMNS to only test 2 pages each
import crawl_jxlc_v2

# Override to stop after 2 pages
original_total_pages = 999

conn = crawl_jxlc_v2.get_conn()

for col in crawl_jxlc_v2.COLUMNS:
    name = col["name"]
    infotypeId = col["infotypeId"]
    divid = col["divid"]
    crawl_jxlc_v2.HEADERS_TEMPLATE["Referer"] = col["referer"]
    
    print(f"\n=== {name} ===")
    html = crawl_jxlc_v2.fetch_page(infotypeId, divid, 1)
    items = crawl_jxlc_v2.parse_page(html)
    tr = __import__("re").search(r'nTotalCount"\s*value="(\d+)"', html)
    total = tr.group(1) if tr else "?"
    print(f"  Page 1: {len(items)} items, total={total}")
    for t, u, d in items[:2]:
        print(f"    {t[:35]:37s} {d:15s}")
    
    # Page 2
    html2 = crawl_jxlc_v2.fetch_page(infotypeId, divid, 2)
    items2 = crawl_jxlc_v2.parse_page(html2)
    print(f"  Page 2: {len(items2)} items")
    
conn.close()
print("\nDone.")
