import subprocess, time, os, sys K="말소등기소유권보존등기말소청구" OUT="tmp" UA="Mozilla/5.0" def fetch(name, url): p=os.path.join(OUT, f"{name}_{K}.xml") if os.path.exists(p) and os.path.getsize(p)>500: print("SKIP(cached)", name); return for delay in (0,12,24): if delay: time.sleep(delay) r=subprocess.run(["curl","-s","--http1.1","-A",UA,"--max-time","60",url],capture_output=True) b=r.stdout if len(b)>500 and b'<' in b: open(p,'wb').write(b); print("OK",name,len(b)); return print("RETRY",name,len(b)) open(p,'wb').write(b); print("FAIL",name,len(b)) jobs=[ ("prec_191635","http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID=191635&type=XML"), ("eflaw_특조법","http://www.law.go.kr/DRF/lawSearch.do?OC=test&target=eflaw&query=%EB%B6%80%EB%8F%99%EC%82%B0%EC%86%8C%EC%9C%A0%EA%B6%8C%20%EC%9D%B4%EC%A0%84%EB%93%B1%EA%B8%B0%20%EB%93%B1%EC%97%90%20%EA%B4%80%ED%95%9C%20%ED%8A%B9%EB%B3%84%EC%A1%B0%EC%B9%98%EB%B2%95&display=100&type=XML"), ("law_238753","http://www.law.go.kr/DRF/lawService.do?OC=test&target=law&MST=238753&type=XML"), ("prec_185818","http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID=185818&type=XML"), ("prec_85052","http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID=85052&type=XML"), ("search_등기규칙","http://www.law.go.kr/DRF/lawSearch.do?OC=test&target=law&query=%EB%B6%80%EB%8F%99%EC%82%B0%EB%93%B1%EA%B8%B0%EA%B7%9C%EC%B9%99&display=20&type=XML"), ("law_266847","http://www.law.go.kr/DRF/lawService.do?OC=test&target=law&MST=266847&type=XML"), ("prec_217361","http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID=217361&type=XML"), ] time.sleep(6) for i,(n,u) in enumerate(jobs): if i: time.sleep(8) fetch(n,u) print("DONE")