- 공공기관2/3 작업본 + 오늘 제출 17곳 D~J 카테고리 셀병합 정상화 - 한국지역난방공사 옵션2(고아셀 F98 수정)+전행 높이17 - 제출_프리랜서2_2026-06-21.zip 생성(17개 xlsx, 2,468행) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
40 lines
2.0 KiB
Python
40 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
import urllib.request, ssl, hashlib, re, io
|
|
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
|
|
def fetch(u):
|
|
try:
|
|
req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"})
|
|
r=urllib.request.urlopen(req,context=ctx,timeout=20)
|
|
raw=r.read()
|
|
final=r.geturl()
|
|
try: html=raw.decode("utf-8")
|
|
except: html=raw.decode("euc-kr","ignore")
|
|
# extract title + main content text
|
|
t=re.search(r'<title>(.*?)</title>',html,re.S)
|
|
title=t.group(1).strip() if t else ""
|
|
# strip tags, collapse ws
|
|
body=re.sub(r'<script.*?</script>','',html,flags=re.S)
|
|
body=re.sub(r'<style.*?</style>','',body,flags=re.S)
|
|
txt=re.sub(r'<[^>]+>',' ',body)
|
|
txt=re.sub(r'\s+',' ',txt).strip()
|
|
return final,title,len(txt),hashlib.md5(txt.encode()).hexdigest()[:10],txt
|
|
except Exception as e:
|
|
return "ERR:"+str(e),"",0,"",""
|
|
pairs=[
|
|
("신재생에너지","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200495","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200150"),
|
|
("환경친화설비","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200362","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200154"),
|
|
("연혁","https://www.kdhc.co.kr/kdhc/bbs/B0000066/list.do?menuNo=200226","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200169"),
|
|
("조직도","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200246","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200319"),
|
|
]
|
|
out=io.open("_cmp_out.txt","w",encoding="utf-8")
|
|
for nm,a,b in pairs:
|
|
fa=fetch(a); fb=fetch(b)
|
|
same = fa[3]==fb[3] and fa[3]!=""
|
|
out.write(f"### {nm} SAME_CONTENT={same}\n")
|
|
out.write(f" A {a}\n final={fa[0]} len={fa[2]} md5={fa[3]} title={fa[1]}\n")
|
|
out.write(f" B {b}\n final={fb[0]} len={fb[2]} md5={fb[3]} title={fb[1]}\n")
|
|
# show distinctive snippet
|
|
out.write(f" A-snip: {fa[4][:200]}\n")
|
|
out.write(f" B-snip: {fb[4][:200]}\n\n")
|
|
out.close(); print("done")
|