import os, ssl, urllib.request, html, re
BASE=os.path.dirname(os.path.abspath(__file__))
ctx=ssl.create_default_context(); ctx.check_hostname=False; ctx.verify_mode=ssl.CERT_NONE
for tag,url in [("stan-cs","https://cs.stanford.edu/"),("stan-grad","https://gradadmissions.stanford.edu/")]:
    try:
        req=urllib.request.Request(url,headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'})
        b=urllib.request.urlopen(req,timeout=12,context=ctx).read()
        raw=b.decode('utf-8',errors='replace')
        t=re.sub(r'<script[\s\S]*?</script>',' ',raw); t=re.sub(r'<style[\s\S]*?</style>',' ',t)
        t=re.sub(r'<[^>]+>',' ',t); t=html.unescape(re.sub(r'\s+',' ',t)).strip()
        print("==",tag,len(b),"B textlen",len(t))
        print(t[:400])
        # challenge 关键词
        for kw in ["challenge","captcha","verify you are human","robot","blocked","forbidden","403"]:
            if kw in t.lower(): print("  !! hits:",kw)
    except Exception as e:
        print("==",tag,"FAIL",type(e).__name__,e)
