#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os, subprocess, time, urllib.parse OUT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "drf_말소등기전세권설정등기말소청구") LOG = os.path.join(OUT, "_log2.txt") def log(s): open(LOG, "a", encoding="utf-8").write(s + "\n"); print(s, flush=True) def fetch(name, params): path = os.path.join(OUT, name + ".xml") if os.path.exists(path) and os.path.getsize(path) > 1000: log("SKIP " + name); return ep = params.pop("_ep") url = "http://www.law.go.kr/DRF/" + ep + "?" + urllib.parse.urlencode(params, encoding="utf-8") for i, d in enumerate([0, 12, 24]): if d: time.sleep(d) r = subprocess.run(["curl", "-sS", "--http1.1", "-A", "Mozilla/5.0", "--max-time", "180", "-o", path, url], capture_output=True, text=True) sz = os.path.getsize(path) if os.path.exists(path) else 0 if r.returncode == 0 and sz > 1000: log("OK %s %d" % (name, sz)); return log("FAIL %s try%d rc=%d sz=%d" % (name, i + 1, r.returncode, sz)) log("GIVEUP " + name) LAWMST = { "L_민법": "284415", "L_부동산등기법": "265377", "L_민사집행법": "268837", "L_민사소송법": "252393", "L_소송촉진법": "286417", "L_특례이율령": "208701", "L_채무자회생법": "267359", } JOBS = [] for n, m in LAWMST.items(): JOBS.append((n, {"_ep": "lawService.do", "OC": "test", "target": "law", "MST": m, "type": "XML"})) JOBS.append(("R_예규1786", {"_ep": "lawService.do", "OC": "test", "target": "admrul", "ID": "2200000106023", "type": "XML"})) JOBS.append(("R_예규1671", {"_ep": "lawService.do", "OC": "test", "target": "admrul", "ID": "2200000105399", "type": "XML"})) for n, p in JOBS: fetch(n, dict(p)); time.sleep(8) log("PHASE2_DONE")