# -*- coding: utf-8 -*-
import urllib.request, ssl, re
from bs4 import BeautifulSoup
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
HDR={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124 Safari/537.36'}
def fetch(u):
    return urllib.request.urlopen(urllib.request.Request(u,headers=HDR),timeout=20,context=ctx).read()

# content page (상징)
for u in ['https://www.komipo.co.kr/kor/content/50/main.do?mnCd=FN02010802',
          'https://www.komipo.co.kr/kor/content/559/main.do?mnCd=FN01200102']:
    html=fetch(u); soup=BeautifulSoup(html,'html.parser')
    print('=== ',u)
    # find main content container candidates
    for sel in ['div.contents','div.contentsArea','div.content','div.sub_content','div.contents_inner','#contents','div.txt','div.board_view','article']:
        el=soup.select_one(sel)
        if el:
            imgs=el.find_all('img')
            print(f'  container {sel}: imgs={len(imgs)}')
    # 공공누리 mark
    kogl=re.findall(r'open(?:type|code)0*\d', html.decode('utf-8','ignore'))
    print('  kogl marks:', set(kogl))
    # all imgs with src
    allim=soup.find_all('img')
    print('  total imgs', len(allim))
    for im in allim[:25]:
        src=im.get('src','');alt=im.get('alt','')
        print('    img', src[:60],'| alt=',alt[:30])

# board page (회의록 다운로드 BRD_000001)
ub='https://www.komipo.co.kr/kor/board/BRD_000001/boardMain.do?mnCd=FN02170203'
html=fetch(ub); txt=html.decode('utf-8','ignore')
print('=== board', ub)
for pat in [r'Total\s*[:：]?\s*([\d,]+)', r'전체\s*([\d,]+)', r'총\s*([\d,]+)\s*건', r'게시물.*?([\d,]+)']:
    m=re.search(pat,txt)
    print('  pat',pat,'->',m.group(0) if m else None)
