import requests, io
from bs4 import BeautifulSoup
hd={"User-Agent":"Mozilla/5.0"}
urls=["https://www.kofpi.or.kr/public/publicInfo_03.do",
      "https://www.kofpi.or.kr/public/publicInfo_03_02.do",
      "https://www.kofpi.or.kr/public/publicInfo_03_03.do"]
out=io.open("_tabs_out.txt","w",encoding="utf-8")
for u in urls:
    try:
        r=requests.get(u,headers=hd,timeout=20)
        r.encoding=r.apparent_encoding
        s=BeautifulSoup(r.content,"html.parser")
        out.write(f"\n===== {u}  status={r.status_code}  final={r.url}\n")
        for tab in s.select("div.tab01, div[class*=tab01], ul.tab, div[class*=tab]"):
            cls=tab.get("class")
            links=tab.select("li a")
            if links:
                out.write(f"  TABDIV class={cls}\n")
                for a in links:
                    out.write(f"     li.{a.find_parent('li').get('class')} | {a.get_text(strip=True)} -> {a.get('href')}\n")
                break
    except Exception as e:
        out.write(f"\n===== {u} ERROR {e}\n")
out.close()
print("done")
