diff options
| author | Yuren Hao <97327730+YurenHao0426@users.noreply.github.com> | 2025-08-06 02:13:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-06 02:13:31 -0700 |
| commit | 2dda168a062841725cd59102bb194c958b214639 (patch) | |
| tree | 1dcd26e92fdd2122e784b0a4b1b60e6df8fef638 /scripts | |
| parent | 2434b68db4d8f86a2d614dc096a2c2cadcb38a91 (diff) | |
| parent | e5cbd188c6fc654e8ababd37922c018bc8527c44 (diff) | |
Merge branch 'main' into l7g40n-codex/test-uiuc-api-cors-responsel7g40n-codex/test-uiuc-api-cors-response
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/scrape.js | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/scripts/scrape.js b/scripts/scrape.js index 93f6a41..d4b2ecb 100644 --- a/scripts/scrape.js +++ b/scripts/scrape.js @@ -2,6 +2,7 @@ import { XMLParser } from "fast-xml-parser"; import fs from "fs/promises"; import path from "path"; import dns from "node:dns"; + import { ProxyAgent } from "undici"; dns.setDefaultResultOrder("ipv4first"); @@ -20,18 +21,23 @@ async function getXML(url) { const res = await fetch(url, { dispatcher }); if (!res.ok) throw new Error(`Request failed: ${res.status} ${url}`); return parser.parse(await res.text()); + } async function scrapeSchedule(year, term) { const catalog = {}; const termRoot = await getXML(`${BASE}/schedule/${year}/${term}.xml`); + const subjects = termRoot.term?.subjects?.subject; if (!subjects) throw new Error(`Unexpected XML structure for ${year} ${term}`); + const subjHrefs = Array.isArray(subjects) ? subjects.map(s => s['@_href']) : [subjects['@_href']]; for (const subjURL of subjHrefs) { const subjXML = await getXML(subjURL); + const courses = subjXML.subject?.courses?.course || []; + const courseList = Array.isArray(courses) ? courses : [courses]; for (const c of courseList) { const courseURL = c['@_href']; |
