# -*- coding: utf-8 -*- import urllib.request, ssl, 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=20,context=ctx).read() u='https://www.komipo.co.kr/kor/content/50/main.do?mnCd=FN02010802' soup=BeautifulSoup(fetch(u),'html.parser') # locate banner01 and a character img, print ancestor chain classes def chain(img): out=[] p=img for _ in range(8): p=p.parent if not p or p.name=='[document]': break out.append(p.name+'.'+'.'.join(p.get('class') or []) + ('#'+p.get('id') if p.get('id') else '')) return ' < '.join(out) for im in soup.find_all('img'): src=im.get('src','') if 'ecomi_main_character' in src or 'banner01' in src: print(src[:50]) print(' ',chain(im));print() # look for editor content div (where real content lives) for sel in ['div.con_area','div.cont_area','div.editor','div.fr-view','div.cont','div.view_cont','div.bbsView','div.sub_cont','div.subContents','.cms_content','.contents .con']: el=soup.select_one(sel) if el: print('FOUND',sel,'imgs',len(el.find_all('img')))