import re,sys,html def load(p): return open(p,encoding='utf-8').read() def cd(s): s=re.sub(r'', r'\1', s, flags=re.S) return html.unescape(re.sub(r'<[^>]+>','',s)).strip() def basic(x): m=lambda t: (re.search(r'<%s>(?:)?'%(t,t), x, re.S).group(1) if re.search(r'<%s>'%t,x) else '?') return m('법령명_한글'), m('공포번호'), m('시행일자'), m('법종구분') def arts(x, nums): out={} for blk in re.findall(r'<조문단위[^>]*>.*?', x, re.S): no=re.search(r'<조문번호>(\d+)', blk) no2=re.search(r'<조문가지번호>(\d+)', blk) if not no: continue key=no.group(1)+('-'+no2.group(1) if no2 else '') if key in nums: eff=re.search(r'<조문시행일자>(\d+)', blk) out[key]=(cd(blk), eff.group(1) if eff else '') return out p=sys.argv[1]; nums=sys.argv[2].split(',') x=load(p) print("=== ", basic(x)) a=arts(x,nums) for n in nums: if n in a: t,e=a[n] print(f"\n--- 제{n}조 (조문시행일 {e}) ---\n{t[:1800]}") else: print(f"\n--- 제{n}조 : 없음")