from playwright.sync_api import sync_playwright
import re,io,json
T={
 200518:"https://www.kdhc.co.kr/kdhc/bbs/B0000099/list.do?menuNo=200518",
 200104:"https://www.kdhc.co.kr/kdhc/bbs/B0000054/list.do?menuNo=200104",
 200125:"https://www.kdhc.co.kr/kdhc/bbs/B0000038/list.do?menuNo=200125",
 200550:"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=5&menuNo=200550",
 200127:"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=2&menuNo=200127",
 200427:"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=3&menuNo=200427",
 200128:"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=1&menuNo=200128",
 200413:"https://www.kdhc.co.kr/kdhc/bbs/B0000073/list.do?menuNo=200413",
 200131:"https://www.kdhc.co.kr/kdhc/bbs/B0000055/list.do?menuNo=200131",
 200175:"https://www.kdhc.co.kr/kdhc/bbs/B0000063/list.do?menuNo=200175",
}
res={}
with sync_playwright() as p:
    b=p.chromium.launch(); pg=b.new_page()
    for mn,u in T.items():
        try:
            pg.goto(u,wait_until='networkidle',timeout=35000)
            pg.wait_for_timeout(1200)
        except Exception as e:
            res[mn]={'err':str(e)[:40]}; continue
        body=pg.inner_text('body')
        empty='게시물이 없습니다' in body or '등록된 게시물이 없' in body
        tot=re.search(r'전체게시물\s*([\d,]+)',body) or re.search(r'전체\s*([\d,]+)\s*건',body)
        pgind=re.search(r'(\d+)\s*/\s*(\d+)\s*페이지',body)
        rows=pg.eval_on_selector_all('table tbody tr','e=>e.length')
        gal=pg.eval_on_selector_all('[class*=gallery] li,[class*=galler] li,[class*=photo] li,[class*=thumb] li,[class*=card] li,ul.list li,.list_wrap li','e=>e.length')
        res[mn]={'empty':empty,'tot':(tot.group(1) if tot else None),'pg':(pgind.groups() if pgind else None),'rows':rows,'gal':gal}
    b.close()
io.open('_pw_norows.json','w',encoding='utf-8').write(json.dumps(res,ensure_ascii=False,indent=1))
for mn,d in res.items(): print(mn,d)
