# -*- coding: utf-8 -*-
import re, sys, io, urllib.request, ssl
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
ctx = ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
hdr={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120 Safari/537.36"}
for u in ["https://grad.berkeley.edu/admissions/application-process/cost/"]:
    try:
        req=urllib.request.Request(u, headers=hdr)
        with urllib.request.urlopen(req, timeout=15, context=ctx) as r:
            body=r.read(250000).decode("utf-8","ignore")
        print("http=200 len=", len(body))
        txt=re.sub(r'<[^>]+>',' ',body); txt=re.sub(r'\s+',' ',txt)
        for m in re.finditer(r'.{60}(\$\s?[0-9,]{3,}|per unit|per semester|tuition|nonresident|resident).{60}', txt, re.I):
            print("  >>", m.group(0)[:180])
    except Exception as e:
        print("ERR", type(e).__name__, str(e)[:80])
