DB_JOB/작업파일/완료/광역_사이트맵/충청북도/_probe6.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

33 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
import sys,io,urllib.request,ssl,re
from bs4 import BeautifulSoup
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
# 충주 sitemap 탐색
print('=== 충주 메인에서 사이트맵 링크 찾기 ===')
h=get('https://www.chungju.go.kr/www/index.do')
if not h.startswith('ERR'):
for m in re.findall(r'href="([^"]*sitemap[^"]*)"',h)[:5]: print(' ',m)
SITES={
'충주':'https://www.chungju.go.kr/www/sitemap.do',
'단양':'https://www.danyang.go.kr/dy21/98',
'영동':'https://www.yd21.go.kr/kr/html/guide/0701.html',
'증평':'https://www.jp.go.kr/kor/sitemap_11.do',
'진천':'https://www.jincheon.go.kr/home/sub.do?menukey=445',
'보은':'https://www.boeun.go.kr/www/index.do',
}
for nm,u in SITES.items():
h=get(u)
if h.startswith('ERR'): print(nm,'접속실패',h[:50]); continue
s=BeautifulSoup(h,'html.parser')
info=[]
for sel in ['li.depth1_item','div.sitemap_box','a.h4','ul.bu','ul#menu_sitemap','ul.ld1','dl','ul.depth1_ul','div.sitemap','.snb','.lnb']:
n=len(s.select(sel))
if n: info.append('%s=%d'%(sel,n))
print('%s len=%d | %s'%(nm,len(h),' '.join(info)))