# -*- coding: utf-8 -*-
import urllib.request, ssl, re
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().decode('utf-8','ignore')
for ub in ['https://www.komipo.co.kr/kor/board/BRD_000001/boardMain.do?mnCd=FN02170203',
           'https://www.komipo.co.kr/esg/board/BRD_000014/boardMain.do?mnCd=ESG04020203']:
    txt=fetch(ub)
    print('===',ub.split('/board/')[1][:20])
    for pat in [r'[Tt]otal[^0-9]{0,8}([\d,]+)', r'([\d,]+)\s*건', r'totalCnt[^0-9]{0,6}([\d,]+)', r'페이지\s*\d+\s*/\s*(\d+)', r'data-total[=\"\']*([\d,]+)']:
        ms=re.findall(pat,txt)
        if ms: print('  ',pat,'->',ms[:5])
    # show snippet around 'total' or '건'
    for kw in ['total','Total','건','게시']:
        i=txt.find(kw)
        if i>0: print('   ctx[%s]:'%kw, re.sub(r'\s+',' ',txt[i-40:i+40]))
