import requests,re
from bs4 import BeautifulSoup
import urllib3; urllib3.disable_warnings()
H={'User-Agent':'Mozilla/5.0'}
urls={
 '사회공헌위원회':"https://www.kdhc.co.kr/kdhc/bbs/B0000008/list.do?menuNo=200106",
 '시민열냉방시설기준':"https://www.kdhc.co.kr/kdhc/cstmrCnter/arclngFclty/list.do?fcltyParntsSe=02&menuNo=200276",
 '안전경영방침(B30)':"https://www.kdhc.co.kr/kdhc/bbs/B0000030/list.do?menuNo=200091",
 '한난사보20-23':"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=2&menuNo=200127",
 '한난사보-19':"https://www.kdhc.co.kr/kdhc/prCnter/cyclb/list.do?prTargetSe=3&menuNo=200427",
 'FAQ':"https://www.kdhc.co.kr/kdhc/bbs/B0000010/list.do?menuNo=200271",
}
for nm,u in urls.items():
    r=requests.get(u,headers=H,timeout=25,verify=False)
    s=BeautifulSoup(r.content,'html.parser')
    pi=s.find(string=re.compile(r'\d+\s*/\s*\d+\s*페이지'))
    pg=re.search(r'(\d+)\s*/\s*(\d+)',pi).groups() if pi else None
    views=set(re.findall(r'view\.do\?[^"\' ]*nttId=(\d+)',r.text))
    cyclb=set(re.findall(r'(?:view|detail)\.do\?[^"\' ]*?(?:cyclbId|nttId|seq)=(\d+)',r.text))
    li_imgs=len(s.select('#contents img, #contents li, .contents li'))
    print(f'== {nm} pages={pg} viewlinks={len(views)} liimg={li_imgs}')
    # show some list item count candidates
    for sel in ['table tbody tr','.gallery li','ul.list li','.list li','dl dt']:
        x=s.select(sel)
        if x: print('   ',sel,len(x))
