DB_JOB/작업파일/완료_1-2주차/2주차/검토_리포트/inspect_lnb.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

49 lines
1.9 KiB
Python

"""성평등가족부와 외교부의 lnb(좌측 메뉴)에서 active 상태 찾기."""
import sys, io, re
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
import requests, urllib3
urllib3.disable_warnings()
s = requests.Session()
s.headers.update({
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0 Safari/537.36',
})
from bs4 import BeautifulSoup
samples = {
'성평등가족부': 'https://www.mogef.go.kr/sp/geq/sp_geq_f001.do',
'외교부': 'https://www.mofa.go.kr/www/wpge/m_3435/contents.do',
}
for site, url in samples.items():
print(f'\n========== {site} ==========')
r = s.get(url, verify=False, timeout=20)
soup = BeautifulSoup(r.text, 'html.parser')
# 1) lnb / sub_menu / left_menu에서 active/on/current 클래스
for el in soup.find_all(['div', 'ul', 'nav']):
cls = ' '.join(el.get('class', []))
if re.search(r'lnb|sub_menu|left|gnb|sideMenu|side_menu|smb', cls, re.IGNORECASE):
# active li
actives = el.select('.on, .active, .current, .sel, [class*=active], [class*=current]')
if actives:
print(f' [{cls}]:')
for a in actives[:6]:
print(f' "{a.get_text(" ", strip=True)[:100]}" (class={" ".join(a.get("class", []))})')
# 2) h2/h3 영역 주변 살펴보기
h2s = soup.select('h2, h3')
for h in h2s[:5]:
print(f' <{h.name}>: "{h.get_text(strip=True)[:60]}" class={" ".join(h.get("class", []))}')
# 3) 페이지 title에서 메뉴 추정 단서
print(f' title: {soup.title.get_text(" ", strip=True)[:150]}')
# 4) meta name=description 등
for m in soup.find_all('meta'):
n = m.get('name', '')
if n in ['description', 'keywords', 'subject']:
print(f' meta {n}: {m.get("content", "")[:100]}')