import subprocess, time, os, sys OUT="tmp/drf_말소폐쇄" os.makedirs(OUT, exist_ok=True) def fetch(name, url, params): path=os.path.join(OUT, name+".xml") if os.path.exists(path) and os.path.getsize(path)>2000: print("skip", name, os.path.getsize(path)); return args=["curl","-sS","-G","--http1.1","-A","Mozilla/5.0","--max-time","90","-o",path] for k,v in params.items(): args += ["--data-urlencode", f"{k}={v}"] args.append(url) for attempt,delay in enumerate([0,12,24]): if delay: time.sleep(delay) r=subprocess.run(args, capture_output=True, text=True) if r.returncode==0 and os.path.exists(path) and os.path.getsize(path)>2000: print("ok", name, os.path.getsize(path)); return print("retry", name, r.returncode, r.stderr[:120], os.path.getsize(path) if os.path.exists(path) else -1) print("FAIL", name) BASE="http://www.law.go.kr/DRF/lawService.do" SEARCH="http://www.law.go.kr/DRF/lawSearch.do" time.sleep(36) jobs=[ ("law_부동산등기법", BASE, {"OC":"test","target":"law","MST":"265377","type":"XML"}), ("law_부동산등기규칙", BASE, {"OC":"test","target":"law","MST":"266847","type":"XML"}), ("law_민법", BASE, {"OC":"test","target":"law","MST":"284415","type":"XML"}), ("law_민사소송법", BASE, {"OC":"test","target":"law","MST":"252393","type":"XML"}), ("law_민사집행법", BASE, {"OC":"test","target":"law","MST":"268837","type":"XML"}), ("law_채무자회생법", BASE, {"OC":"test","target":"law","MST":"267359","type":"XML"}), ] for i,(n,u,p) in enumerate(jobs): if i: time.sleep(8) fetch(n,u,p)