# -*- coding: utf-8 -*-
"""抓取 grad.ucla.edu 全部 programs 链接落盘。"""
import re, urllib.request, gzip, ssl, io
req = urllib.request.Request('https://grad.ucla.edu/', headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'})
ctx = ssl.create_default_context(); ctx.check_hostname = False; ctx.verify_mode = ssl.CERT_NONE
raw = urllib.request.urlopen(req, timeout=30, context=ctx).read()
if raw[:2] == b'\x1f\x8b':
    raw = gzip.decompress(raw)
html = raw.decode('utf-8', 'ignore')
locs = sorted(set(re.findall(r'href="(https://grad\.ucla\.edu/programs/[^"]+)"', html)))
io.open('_r376_ucla_links.txt', 'w', encoding='utf-8').write('\n'.join(locs))
print('count', len(locs))
for l in locs:
    low = l.lower()
    if any(k in low for k in ['financial', 'electrical', 'computer-science', 'statistic', 'data-science', 'mechanical', 'material', 'bioengineering', 'chemical']):
        print(l)
