- 공공기관2/3 작업본 + 오늘 제출 17곳 D~J 카테고리 셀병합 정상화 - 한국지역난방공사 옵션2(고아셀 F98 수정)+전행 높이17 - 제출_프리랜서2_2026-06-21.zip 생성(17개 xlsx, 2,468행) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
import requests, re, json, sys, time
|
|
from bs4 import BeautifulSoup
|
|
from urllib.parse import urljoin
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
H={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'}
|
|
sess=requests.Session(); sess.headers.update(H)
|
|
rows=json.load(open(r'작업파일/공공기관2/12.한국철도공사/_cur.json',encoding='utf-8'))
|
|
|
|
def get(u):
|
|
for _ in range(3):
|
|
try: return sess.get(u,timeout=30)
|
|
except: time.sleep(1.5)
|
|
return None
|
|
|
|
out={}
|
|
for o in rows:
|
|
u=o['K'] or ''
|
|
if 'contents.do' not in u: continue
|
|
r=get(u)
|
|
if not r: out[o['r']]={'err':1}; continue
|
|
s=BeautifulSoup(r.content,'html.parser')
|
|
tl=s.select_one('ul.tab_list')
|
|
tabs=[]
|
|
if tl:
|
|
for li in tl.select('li.tab_item'):
|
|
a=li.find('a',href=True)
|
|
if not a: continue
|
|
sp=a.find('span')
|
|
lab=(sp.get_text(strip=True) if sp else a.get_text(strip=True))
|
|
active='active' in (li.get('class') or [])
|
|
tabs.append({'label':lab,'href':a['href'],'active':active})
|
|
out[o['r']]={'tabs':tabs,'ntab':len(tabs)}
|
|
if len(tabs)>1:
|
|
print(o['r'], o['F'] or o['E'] or o['D'], '=>', [(t['label'],t['href'].split('key=')[-1],'*' if t['active'] else '') for t in tabs])
|
|
json.dump(out, open(r'작업파일/공공기관2/12.한국철도공사/_tabscan.json','w',encoding='utf-8'),ensure_ascii=False,indent=0)
|
|
print('DONE pages scanned', len(out))
|