import subprocess, time, os, sys OUT="tmp/drf_점유회수반환청구의소" os.makedirs(OUT, exist_ok=True) jobs=[ ("law_민법.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=law&MST=284415&type=XML"), ("law_민사소송법.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=law&MST=252393&type=XML"), ("law_민사집행법.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=law&MST=268837&type=XML"), ("law_소촉법.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=law&MST=286417&type=XML"), ("law_회생파산.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=law&MST=267359&type=XML"), ("prec_226791.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=prec&ID=226791&type=XML"), ("prec_207746.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=prec&ID=207746&type=XML"), ("prec_237303.xml","http://www.law.go.kr/DRF/lawService.do","OC=test&target=prec&ID=237303&type=XML"), ] for name,url,q in jobs: dest=os.path.join(OUT,name) if os.path.exists(dest) and os.path.getsize(dest)>2000: print("skip",name); continue ok=False for attempt in (1,2): r=subprocess.run(["curl","-s","--http1.1","-A","Mozilla/5.0","--max-time","90","-o",dest,url+"?"+q]) sz=os.path.getsize(dest) if os.path.exists(dest) else 0 print(name,"attempt",attempt,"rc",r.returncode,"size",sz, flush=True) if r.returncode==0 and sz>2000: ok=True; break time.sleep(12) if not ok: print("FAIL",name, flush=True) time.sleep(8)