# -*- coding: utf-8 -*-
import sys,io
sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
from playwright.sync_api import sync_playwright
ROWS={
 'r16_자체공시a':'https://www.ksponco.or.kr/menu.es?mid=a10109020800',
 'r17_자체공시b':'https://www.ksponco.or.kr/menu.es?mid=a10109020900',
 'r54_협력기관':'https://www.ksponco.or.kr/menu.es?mid=a10305000000',
 'r56_홍보동영상':'https://www.ksponco.or.kr/menu.es?mid=a10307000000',
 'r104_ESG경영':'https://www.ksponco.or.kr/menu.es?mid=a10506000000',
 'r42_고객서비스헌장':'https://www.ksponco.or.kr/menu.es?mid=a10202010000',
 'r111_윤리경영활동':'https://www.ksponco.or.kr/menu.es?mid=a10502050000',
 'r132_홈피이용안내':'https://www.ksponco.or.kr/menu.es?mid=a10705000000',
}
dec=r"logo|icon|btn|mark_|sns|footer|header|banner|bg_|sprite|blank|no_img|arrow|family|common|opentype|btn_|ico_"
with sync_playwright() as p:
    br=p.chromium.launch(headless=True); ctx=br.new_context(ignore_https_errors=True,viewport={'width':1280,'height':2200})
    for nm,u in ROWS.items():
        pg=ctx.new_page()
        try:
            pg.goto(u,wait_until='networkidle',timeout=30000); pg.wait_for_timeout(1200)
            r=pg.evaluate("""(dec)=>{
              const re=new RegExp(dec,'i');
              let cont=document.querySelector('#contents,.contents,#content,.board_view,.view_cont,.cont,.sub_cont,.bbs_view')||document.body;
              let imgs=[...cont.querySelectorAll('img')].filter(im=>im.naturalWidth>=150&&im.naturalHeight>=110&&!re.test(im.src)).map(im=>im.src.split('/').pop().slice(0,26)+' '+im.naturalWidth+'x'+im.naturalHeight);
              let vid=[...cont.querySelectorAll('video,iframe')].filter(v=>/youtube|youtu\.be|vimeo|player/i.test(v.src||'')).length;
              return {n:imgs.length,imgs:imgs.slice(0,8),vid};
            }""",dec)
            print(nm,'::',r)
        except Exception as e:
            print(nm,'ERR',str(e)[:40])
        pg.close()
    br.close()
