import sys, io sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') import urllib.request, ssl, re ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE hdr={'User-Agent':'Mozilla/5.0'} def fetch(url): req=urllib.request.Request(url, headers=hdr) with urllib.request.urlopen(req, context=ctx, timeout=25) as r: return r.read().decode('utf-8','replace') def content_imgs(html): # extract main content area #contents or .contents and find non-decorative imgs m=re.search(r'id="contents"(.*?)(?:||]*src="([^"]*)"[^>]*>', area) deco=re.compile(r'move\.png|no[-_]?img|blank|spacer|icon|btn_|bullet|/common/|opentype', re.I) real=[s for s in imgs if not deco.search(s)] return imgs, real for pg in range(10): url=f'https://www.asan.go.kr/main/cms/?no=55&pg={pg}' html=fetch(url) t=re.search(r']*class="[^"]*(?:tit|title)[^"]*"[^>]*>(.*?)]+>','',t.group(1)).strip() if t else '' allimg, real = content_imgs(html) ot=re.search(r'img_opentype_(\d)', html) # detect tables, embeds, video has_table=']*class="[^"]*search-list[^"]*"[^>]*>(.*?)', html, re.S) if m: seg=m.group(1) print(re.sub(r'\s+',' ', seg)[:1500])