# -*- coding: utf-8 -*-
import urllib.request, ssl, hashlib, re, io
from bs4 import BeautifulSoup
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
def body(u):
    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")
    # try common content containers
    for sel in ["#content","#contents","#contens",".contents",".content",".sub_content","#container .cont"]:
        el=soup.select_one(sel)
        if el and len(el.get_text(strip=True))>30:
            txt=re.sub(r'\s+',' ',el.get_text(" ",strip=True))
            imgs=[i.get('src','') for i in el.find_all('img')]
            return sel,txt,imgs
    return "NONE","",[]
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/main/contents.do?menuNo=200246","https://www.kdhc.co.kr/kdhc/main/contents.do?menuNo=200319"),
]
out=io.open("_cmp2_out.txt","w",encoding="utf-8")
for nm,a,b in pairs:
    sa,ta,ia=body(a); sb,tb,ib=body(b)
    out.write(f"### {nm}  BODY_SAME={ta==tb and ta!=''}  (selA={sa} selB={sb})\n")
    out.write(f"  A[{len(ta)}]: {ta[:300]}\n")
    out.write(f"  B[{len(tb)}]: {tb[:300]}\n")
    out.write(f"  A imgs: {ia}\n  B imgs: {ib}\n\n")
out.close(); print("done")
