DB_JOB/_스크립트/_probe_jeonbuk6.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

47 lines
2.4 KiB
Python

"""6차: 완주 메뉴/사이트맵 확정 + 부안 대분류 라벨 확인."""
import re, warnings
import requests
from bs4 import BeautifulSoup
warnings.filterwarnings('ignore')
UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
def fetch(url, t=20):
r = requests.get(url, timeout=t, verify=False, headers={'User-Agent': UA})
meta = re.search(rb'<meta[^>]*charset=["\']?\s*([\w-]+)', r.content[:4096], re.I)
r.encoding = meta.group(1).decode('ascii','ignore') if meta else r.apparent_encoding
return r
# 부안 대분류 라벨: 각 depth_boxcon의 strong/p 텍스트
print('=== 부안 대분류(D) 라벨 ===')
soup = BeautifulSoup(fetch('https://www.buan.go.kr/index.buan?contentsSid=1').text, 'html.parser')
nav = soup.select_one('nav#onmenu')
top = nav.find('ul')
for li in top.find_all('li', recursive=False):
a0 = li.find('a', recursive=False)
box = li.find('div', class_='depth_boxcon')
strong = box.find('strong') if box else None
p = box.find('p') if box else None
print(' topA=', repr((a0.get_text().strip()[:20]) if a0 else ''),
'| strong=', repr(strong.get_text().strip()[:20] if strong else ''),
'| p=', repr(p.get_text(' ',strip=True)[:25] if p else ''))
# 완주: 전체 a 중 contentUid 사이트맵/메가메뉴 흔적. gnb mega menu 클래스 탐색
print('\n=== 완주 메뉴 구조 탐색 ===')
soup = BeautifulSoup(fetch('https://www.wanju.go.kr/index.9is').text, 'html.parser')
# 모든 div/ul 중 a>=30 이며 menuUid/contentUid href 다수인 것
for el in soup.find_all(['div','ul','nav']):
cls = ' '.join(el.get('class', [])); idv = el.get('id','')
n_a = len(el.find_all('a'))
if n_a >= 30:
sample = el.find('a', href=re.compile(r'contentUid|menuUid'))
print(f' <{el.name} id={idv!r} class={cls!r}> a={n_a}',
('| 샘플=' + (sample.get('href')[:60] if sample else 'none')))
# 사이트맵 페이지 후보: 전주처럼 index.9is?contentUid= 의 sitemap_Warp
# 완주 모든 contentUid 수집 후 'sitemap_Warp' 또는 'sitemap' 포함 페이지 찾기엔 비용 큼.
# 대신 footer 영역 a 전부 출력
foot = soup.find('footer') or soup.select_one('div.footer, #footer')
if foot:
print(' footer a:')
for a in foot.find_all('a')[:40]:
t=(a.get_text() or '').strip()
if t: print(' ', repr(t[:18]), (a.get('href') or '')[:60])