# -*- coding: utf-8 -*- import sys,io,urllib.request,ssl,re sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8') ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE def get(u): try: req=urllib.request.Request(u,headers={'User-Agent':'Mozilla/5.0'}) return urllib.request.urlopen(req,timeout=20,context=ctx).read().decode('utf-8','ignore') except Exception as e: return 'ERR%s'%e import openpyxl SITES={'옥천':'5.옥천군\\충청북도_옥천군.xlsx','음성':'6.음성군\\충청북도_음성군.xlsx', '제천':'7.제천시\\충청북도_제천시.xlsx','청주':'10.청주시\\충청북도_청주시.xlsx'} for nm,F in SITES.items(): wb=openpyxl.load_workbook(F); ws=wb.active # 첫 게시판 url bu=None for r in range(3,ws.max_row+1): if ws.cell(r,12).value=='게시판': bu=ws.cell(r,11).value; break h=get(bu) if bu else '' # 카운트 패턴 후보 pats={'게시물N':r'게시물[^\d]{0,15}([\d,]+)','총 N건':r'총\s*([\d,]+)\s*건', 'total':r'total[^\d]{0,8}([\d,]+)','건수':r'([\d,]+)\s*건','Total:':r'Total[^\d]{0,8}([\d,]+)'} found={k:(re.search(p,h).group(0)[:25] if re.search(p,h) else None) for k,p in pats.items()} print(nm, bu[:60] if bu else None) for k,v in found.items(): if v: print(' ',k,'=>',v)