import re,sys def strip_cdata(x): return re.sub(r'', r'\1', x, flags=re.S) def arts(path): s=strip_cdata(open(path,encoding='utf-8').read()) out={} for m in re.finditer(r'<조문단위[^>]*>(.*?)', s, re.S): b=m.group(1) no=(re.search(r'<조문번호>(.*?)',b) or [None,''])[1] gaji=(re.search(r'<조문가지번호>(.*?)',b) or [None,''])[1] key=no+('의'+gaji if gaji else '') txt=[] c=(re.search(r'<조문내용>(.*?)',b,re.S) or [None,''])[1] txt.append(c.strip()) for h in re.finditer(r'<항내용>(.*?)',b,re.S): txt.append(h.group(1).strip()) for h in re.finditer(r'<호내용>(.*?)',b,re.S): txt.append(h.group(1).strip()) for h in re.finditer(r'<목내용>(.*?)',b,re.S): txt.append(h.group(1).strip()) out[key]='\n'.join(t for t in txt if t) return out def buchik(path): s=strip_cdata(open(path,encoding='utf-8').read()) return [m.group(1).strip() for m in re.finditer(r'<부칙내용>(.*?)',s,re.S)] if __name__=="__main__": p=sys.argv[1]; a=arts(p) for k in sys.argv[2:]: print("### 제%s조"%k); print(a.get(k,"(없음)")); print()