# -*- coding: utf-8 -*-
import sys,io
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
from playwright.sync_api import sync_playwright
C={
 'r43_고객헌장':"https://www.nypi.re.kr/board?menuKey=Thgr6HhSqf&bbsId=BOARD00030",
 'r48_사전정보공개':"https://www.nypi.re.kr/board?menuKey=&bbsId=BOARD00041",
 'r52_공공데이터개방':"https://www.nypi.re.kr/board?menuKey=PxtUOCbTJ1&bbsId=BOARD00038",
}
with sync_playwright() as p:
    br=p.chromium.launch(headless=True); ctx=br.new_context(ignore_https_errors=True,viewport={'width':1280,'height':1600})
    for nm,u in C.items():
        pg=ctx.new_page()
        try:
            pg.goto(u,wait_until='networkidle',timeout=30000); pg.wait_for_timeout(1200)
            r=pg.evaluate(r"""()=>{
              const body=document.body.innerText;
              const hasTotal=/총\s*\d|전체\s*\d|건수|페이지/.test(body);
              const rows=document.querySelectorAll('table tbody tr, .board_list li, ul.list li').length;
              const pager=document.querySelectorAll('.paging a, .pagination a, [class*=paging] a').length;
              const search=document.querySelectorAll('input[type=search], .search_area, [class*=search] input').length;
              return {hasTotal, rows, pager, search, title:document.title.slice(0,35)};
            }""")
            print(nm,'::',r)
        except Exception as e:
            print(nm,'ERR',str(e)[:40])
        pg.close()
    br.close()
