- 공공기관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>
36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import sys,io,json
|
|
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
|
|
from playwright.sync_api import sync_playwright
|
|
with sync_playwright() as p:
|
|
br=p.chromium.launch(headless=True)
|
|
ctx=br.new_context(ignore_https_errors=True,viewport={'width':1920,'height':1080},
|
|
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120 Safari/537.36')
|
|
pg=ctx.new_page()
|
|
pg.goto("https://www.nypi.re.kr/",wait_until='networkidle',timeout=40000); pg.wait_for_timeout(2000)
|
|
# hover 모든 1depth
|
|
try:
|
|
tops=pg.query_selector_all('#gnb>ul>li, .gnb>ul>li, nav>ul>li, header li')
|
|
for e in tops[:10]:
|
|
try: e.hover(timeout=400); pg.wait_for_timeout(150)
|
|
except: pass
|
|
except: pass
|
|
r=pg.evaluate(r"""()=>{
|
|
function txt(a){return (a.textContent||'').trim().replace(/\s+/g,' ');}
|
|
// 가장 a많은 ul 컨테이너
|
|
let best=null,bn=0;
|
|
document.querySelectorAll('ul').forEach(u=>{const n=u.querySelectorAll('a').length; if(n>bn&&n<200){bn=n;best=u;}});
|
|
let tree=[];
|
|
if(best){
|
|
const top=best.closest('nav')||best.parentElement||best;
|
|
top.querySelectorAll(':scope > ul > li, :scope > li').forEach(li=>{
|
|
const a=li.querySelector('a'); if(!a)return;
|
|
const subs=[...li.querySelectorAll('ul a')].map(x=>txt(x)).filter(Boolean);
|
|
tree.push({d1:txt(a),subs:subs.slice(0,30)});
|
|
});
|
|
}
|
|
return tree.slice(0,15);
|
|
}""")
|
|
print(json.dumps(r,ensure_ascii=False)[:1500])
|
|
br.close()
|