import subprocess, time, os OUT="tmp/drf_사해행위취소청구" os.makedirs(OUT,exist_ok=True) targets=[("prec_2012da2743","179572"),("prec_2003da6200","83073"), ("prec_67da1839","156426"),("prec_2006da1442","140244"), ("prec_99da23468","192147")] def fetch(name,pid): url=f"http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID={pid}&type=XML" p=os.path.join(OUT,name+".xml") for attempt in (1,2): r=subprocess.run(["curl","-s","--http1.1","-A","Mozilla/5.0","-o",p,url],capture_output=True) if r.returncode==0 and os.path.getsize(p)>500: return f"{name}: OK {os.path.getsize(p)} bytes" time.sleep(12) return f"{name}: FAIL" for i,(n,pid) in enumerate(targets): if os.path.exists(os.path.join(OUT,n+".xml")) and os.path.getsize(os.path.join(OUT,n+".xml"))>500: print(n,"cached"); continue print(fetch(n,pid),flush=True) if i < len(targets)-1: time.sleep(8)