# -*- coding: utf-8 -*-
import io, sys, os, re, html, json
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
B = r"D:\work buddy\2026-11-05-14-15-52"
h = open(os.path.join(B,"raw_gatech.html"),encoding="utf-8").read()
i = h.find('id="alltextcontainer"')
j = h.find('id="bachelorstextcontainer"')
seg = h[i:j if j>0 else len(h)]
lis = re.findall(r"<li>(.*?)</li>", seg, re.S)
print("li 数:", len(lis))

rows=[]
for li in lis:
    links = re.findall(r'href="([^"]+)"[^>]*>(.*?)</a>', li, re.S)
    deg = [html.unescape(re.sub(r"<[^>]+>","",d)).strip() for _,d in links]
    hrefs = [u for u,_ in links]
    name = re.sub(r"<a [^>]*>.*?</a>","",li,flags=re.S)
    name = html.unescape(re.sub(r"<[^>]+>","",name)).replace("\xa0"," ").strip()
    name = name.split(".")[0].strip().rstrip(",").strip()
    if not name: continue
    rows.append({"name":name,"deg":deg,"hrefs":hrefs})

json.dump(rows, open(os.path.join(B,"raw_gatech.json"),"w",encoding="utf-8"), ensure_ascii=False, indent=1)
for r in rows:
    print(f"{','.join(r['deg']):28}|{r['name']}")
