공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
"""진천군 div.sitemap outline."""
|
|
import 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'
|
|
H = {'User-Agent': UA}
|
|
|
|
r = requests.get('https://www.jincheon.go.kr/home/sub.do?menukey=445', headers=H, timeout=15, verify=False)
|
|
r.encoding = r.apparent_encoding
|
|
soup = BeautifulSoup(r.text, 'html.parser')
|
|
|
|
def outline(el, d=0, max_lines=70, lines=None):
|
|
if lines is None: lines = []
|
|
if len(lines) >= max_lines: return lines
|
|
name = el.name
|
|
cls = ' '.join(el.get('class', []))
|
|
eid = el.get('id', '')
|
|
lbl = name
|
|
if eid: lbl += f'#{eid}'
|
|
if cls: lbl += '.' + cls.replace(' ', '.')
|
|
if name == 'a':
|
|
t = el.get_text(strip=True)[:40]
|
|
h = el.get('href', '')[:80]
|
|
lines.append(' ' * d + f'{lbl} "{t}" → {h}')
|
|
else:
|
|
lines.append(' ' * d + lbl)
|
|
for c in el.find_all(recursive=False):
|
|
if c.name in ('script', 'style'): continue
|
|
outline(c, d+1, max_lines, lines)
|
|
if len(lines) >= max_lines: return lines
|
|
return lines
|
|
|
|
el = soup.select_one('div.sitemap') or soup.select_one('ul.gnb-wrap')
|
|
if el:
|
|
print(f'Container: {el.name}.{" ".join(el.get("class",[]))} a={len(el.find_all("a"))}')
|
|
for line in outline(el, max_lines=60):
|
|
print(' ', line)
|