from playwright.sync_api import sync_playwright
import re
targets={
 '사회공헌위원회(B8,200106)':"https://www.kdhc.co.kr/kdhc/bbs/B0000008/list.do?menuNo=200106",
 '시민열냉방시설기준(200276)':"https://www.kdhc.co.kr/kdhc/cstmrCnter/arclngFclty/list.do?fcltyParntsSe=02&menuNo=200276",
 '안전경영방침(B30,200091)':"https://www.kdhc.co.kr/kdhc/bbs/B0000030/list.do?menuNo=200091",
 '한난사보20-23(200127)':"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=2&menuNo=200127",
 '한난사보-19(200427)':"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=3&menuNo=200427",
 'FAQ(B10,200271)':"https://www.kdhc.co.kr/kdhc/bbs/B0000010/list.do?menuNo=200271",
}
with sync_playwright() as p:
    b=p.chromium.launch()
    pg=b.new_page()
    for nm,u in targets.items():
        try:
            pg.goto(u,wait_until='networkidle',timeout=30000)
        except Exception as e:
            print(nm,'GOTO ERR',str(e)[:50]); continue
        body=pg.inner_text('body')
        pgind=re.search(r'(\d+)\s*/\s*(\d+)\s*페이지',body)
        tot=re.search(r'전체게시물\s*([\d,]+)',body)
        # count rows / gallery
        rows=pg.eval_on_selector_all('table tbody tr','els=>els.length')
        gal=pg.eval_on_selector_all('.gallery li, [class*=gallery] li, .photo li, [class*=thumb] li','els=>els.length')
        faq=pg.eval_on_selector_all('dl.faq dt, [class*=faq] dt, [class*=faq] li','els=>els.length')
        print(f'{nm}: pageind={pgind.groups() if pgind else None} 전체={tot.group(1) if tot else None} rows={rows} gal={gal} faq={faq}')
    b.close()
