DB_JOB/작업파일/완료/광역_사이트맵/충청북도/_probe_M.py
hehihoho3 df16c98366 백업: DB수집 전체 스냅샷 (공공기관2 정리 전)
공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 18:15:40 +09:00

27 lines
1.3 KiB
Python

# -*- 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)