import subprocess, sys, time, os OUT = "tmp/drf_말소등기토지의일부만에관하여말소등기청구" def get(url, name, tries=3): path = os.path.join(OUT, name) if os.path.exists(path) and os.path.getsize(path) > 500: print("skip(exists)", name); return delays = [0, 12, 24] for i in range(tries): if delays[i]: time.sleep(delays[i]) r = subprocess.run(["curl","-sS","--http1.1","-A","Mozilla/5.0","--max-time","60","-o",path,url]) if r.returncode == 0 and os.path.exists(path) and os.path.getsize(path) > 500: print("ok", name, os.path.getsize(path)); return print("retry", name, "rc=", r.returncode, "size=", os.path.getsize(path) if os.path.exists(path) else -1) print("FAIL", name) jobs = [ ("http://www.law.go.kr/DRF/lawService.do?OC=test&target=admrul&ID=2200000106023&type=XML", "admrul_1786.xml"), ("http://www.law.go.kr/DRF/lawService.do?OC=test&target=prec&ID=210765&type=XML", "prec_210765.xml"), ("http://www.law.go.kr/DRF/lawSearch.do?OC=test&target=prec&search=2&query=2016%EB%8B%A46309&display=100&type=XML", "search_2016da6309.xml"), ("http://www.law.go.kr/DRF/lawSearch.do?OC=test&target=prec&search=2&query=71%EB%8B%A41867&display=100&type=XML", "search_71da1867.xml"), ("http://www.law.go.kr/DRF/lawSearch.do?OC=test&target=prec&search=2&query=80%EB%8B%A41819&display=100&type=XML", "search_80da1819.xml"), ] time.sleep(36) for url, name in jobs: get(url, name) time.sleep(8)