공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import requests, sys, re
|
|
from bs4 import BeautifulSoup
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
base = 'https://www.seocheon.go.kr'
|
|
url = base + '/prog/ioCateData/kor/sub01_02_02/list.do'
|
|
H = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}
|
|
|
|
def get(u):
|
|
r = requests.get(u, headers=H, timeout=20, verify=False)
|
|
r.encoding = r.apparent_encoding or 'utf-8'
|
|
return r.text
|
|
|
|
import urllib3
|
|
urllib3.disable_warnings()
|
|
|
|
html = get(url)
|
|
soup = BeautifulSoup(html, 'html.parser')
|
|
|
|
print('=== basic_tab ===')
|
|
for ul in soup.select('ul.basic_tab'):
|
|
for li in ul.select('li'):
|
|
a = li.find('a')
|
|
txt = ' '.join(li.get_text().split())
|
|
href = a.get('href') if a else ''
|
|
on = 'ON' if 'on' in (li.get('class') or []) else ''
|
|
print(f' [{on}] {txt} -> {href}')
|
|
|
|
print('=== slave_tab (default page b01) ===')
|
|
for ul in soup.select('ul.slave_tab'):
|
|
for li in ul.select('li'):
|
|
a = li.find('a')
|
|
txt = ' '.join(li.get_text().split())
|
|
href = a.get('href') if a else ''
|
|
on = 'ON' if 'on' in (li.get('class') or []) else ''
|
|
print(f' [{on}] {txt} -> {href}')
|
|
|
|
print('=== total count hints ===')
|
|
# find total
|
|
for kw in ['총','Total','건']:
|
|
for el in soup.find_all(string=re.compile(kw)):
|
|
s=' '.join(el.split())
|
|
if s and len(s)<40:
|
|
print(' ', repr(s))
|