# -*- coding: utf-8 -*- import urllib.request, ssl, re, io from bs4 import BeautifulSoup ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE def body(u): try: req=urllib.request.Request(u,headers={"User-Agent":"Mozilla/5.0"}) raw=urllib.request.urlopen(req,context=ctx,timeout=20).read() soup=BeautifulSoup(raw,"html.parser") for sel in ["#content","#contents",".contents",".content"]: el=soup.select_one(sel) if el and len(el.get_text(strip=True))>30: # remove the breadcrumb / share / local-subnav noise by taking text after '프린트' txt=re.sub(r'\s+',' ',el.get_text(" ",strip=True)) core=txt.split("프린트",1)[-1] return core.strip()[:260] return "(no content div)" except Exception as e: return "ERR:"+str(e) pairs=[ ("연혁(게시판vs페이지)","https://www.kdhc.co.kr/kdhc/bbs/B0000066/list.do?menuNo=200226","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200169"), ("기본방향(발전배열vs연료전지)","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200598","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200601"), ("기본요금(발전배열vs연료전지)","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200599","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200602"), ("사용량요금(발전배열vs연료전지)","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200600","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200603"), ] out=io.open("_cmp3_out.txt","w",encoding="utf-8") for nm,a,b in pairs: ca=body(a); cb=body(b) out.write(f"### {nm} SAME={ca==cb and not ca.startswith('ERR')}\n A: {ca}\n B: {cb}\n\n") out.close(); print("done")