import subprocess,time,os OUT="tmp/drf_점유회수반환청구의소" for pid in ["165603","236459","199215","203507"]: dest=os.path.join(OUT,"prec_%s.xml"%pid) if os.path.exists(dest) and os.path.getsize(dest)>2000: print("skip",pid); continue for a in (1,2): r=subprocess.run(["curl","-s","--http1.1","-A","Mozilla/5.0","--max-time","90","-o",dest, "http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID=%s&type=XML"%pid]) sz=os.path.getsize(dest) if os.path.exists(dest) else 0 print(pid,"attempt",a,"rc",r.returncode,"size",sz,flush=True) if r.returncode==0 and sz>2000: break time.sleep(12) time.sleep(8)