# -*- coding: utf-8 -*-
import os
from playwright.sync_api import sync_playwright
os.makedirs('_nshots_tab',exist_ok=True)
pages={
 '복리후생_561':'https://www.komipo.co.kr/kor/content/561/main.do?mnCd=FN01200104',
 '인재육성_560':'https://www.komipo.co.kr/kor/content/560/main.do?mnCd=FN01200103',
 '안전조직_492':'https://www.komipo.co.kr/esg/content/492/main.do?mnCd=ESG03050104',
}
with sync_playwright() as p:
    b=p.chromium.launch()
    pg=b.new_page(viewport={'width':1200,'height':2400},ignore_https_errors=True)
    for name,url in pages.items():
        try:
            pg.goto(url,wait_until='networkidle',timeout=30000)
        except: 
            try: pg.goto(url,wait_until='load',timeout=30000)
            except Exception as e: print('ERR',name,str(e)[:50]); continue
        pg.wait_for_timeout(1500)
        el=pg.query_selector('#content')
        try:
            (el or pg).screenshot(path=f'_nshots_tab/{name}.png')
            print('shot',name)
        except Exception as e: print('shoterr',name,str(e)[:50])
    b.close()
