# -*- coding: utf-8 -*- import ssl,urllib.request,re from bs4 import BeautifulSoup ctx=ssl.create_default_context();ctx.check_hostname=False;ctx.verify_mode=ssl.CERT_NONE HDR={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/124 Safari/537.36'} def fetch(u): return urllib.request.urlopen(urllib.request.Request(u,headers=HDR),timeout=25,context=ctx).read() UI=re.compile(r'banner|/common/|icon|btn|logo|bullet|sprite|blank|no_img|arrow|/dot|/bg|popup|/sns',re.I) B='https://www.komipo.co.kr' tests=[('전사 캠페인','BRD_000096','18525','ESG03030203'),('인권경영 자료공유','BRD_000097','21898','ESG03030303')] for lab,brd,idx,mn in tests: ok=False for tmpl in ['/esg/board/%s/boardView.do?bbsIdx=%s&mnCd=%s'%(brd,idx,mn), '/esg/board/%s/boardView.do?idx=%s&mnCd=%s'%(brd,idx,mn)]: try: s=BeautifulSoup(fetch(B+tmpl),'html.parser') cont=s.select_one('#content') or s txt=cont.get_text(' ',strip=True) imgs=[im.get('src') for im in cont.find_all('img') if 'getImage' in im.get('src','') and not UI.search(im.get('src',''))] if len(txt)>50: name=tmpl.split('?')[0].split('/')[-1] print('%s: %s OK content imgs=%d %s'%(lab,name,len(imgs),imgs[:2])) ok=True; break except Exception: pass if not ok: print(lab,'no view template worked')