Skip to content

fix(spider): parse restructured GC course detail pages - #67

Merged
JackyTJie merged 1 commit into
mainfrom
fix/orc-parser-gc-restructure
Sep 3, 2026
Merged

JackyTJie merged 1 commit into
mainfrom
fix/orc-parser-gc-restructure

Conversation

@JackyTJie

Copy link
Copy Markdown
Contributor

Problem

The GC course site restructured its course detail pages: the labelled fields (Instructors, Credits, Pre-requisites, Description, Course Topics) are now wrapped in nested divs inside the detail block, and topics are listed as plain <p>s instead of <li>s.

The current parser (_crawl_course_data) iterates only the direct children of the detail block and extracts topics via find_all("li"), so after the restructure it captured nothing but the <h2> course code/title — and because import_department wholesale-overwrites on each crawl, stored descriptions/topics kept getting wiped with empty values. Verified live: all 412 courses in the DB have course_topics: null / empty descriptions.

Fix

  • Rewrite _crawl_course_data to parse the flattened text stream of the detail block (get_text(separator="\n")), grouping lines by section marker. Extraction no longer depends on the wrapper-div layout or list tags.
  • Guard import_department: when a page carries none of the known section markers, skip the import instead of overwriting stored data — so a future layout change can't silently wipe course fields again. Records without the new key default to "recognized" for backward compatibility.

Verification

Ran the patched parser (through the repo's own Django env) against live GC pages, 6 random courses — all parsed correctly:

Course Topics Instructors Description
MATH2150J Calculus III 18 4 294 chars
ECE4130J Monolithic Amplifier Circuits 5 1 528 chars
ME4810J Manufacturing Processes 0 880 chars
VM503 Numerical methods 0 1 – (page truly empty)
BUS4220J E-Business Management 10 158 chars
CS2810J Data Structures and Algorithms 10 2 298 chars

The old parser produced only code/title for the same pages. No DB writes during testing; ruff check/format clean (3 pre-existing warnings on untouched lines).

Note

Not covered here: the crawler's base domain on main is still www.ji.sjtu.edu.cn; the canonical-domain switch to gc.sjtu.edu.cn lives on the local deploy branch and should land separately.

GC site moved course detail fields (topics as <p>s, not <li>s) inside
nested wrapper divs, breaking the direct-children parser: only course
code/title survived, and each crawl overwrote stored descriptions and
topics with empty values.

Parse the flattened text stream of the detail block, grouping lines by
section marker, so field extraction no longer depends on child layout
or list tags. Skip import of pages whose structure was not recognized
so future layout changes cannot wipe existing course data again.

Verified against live GC pages: 6 random courses parse correctly
(up to 18 topics, descriptions, prereqs, instructors, credits); the
previous parser extracted none of these fields.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@JackyTJie
JackyTJie merged commit d4473f1 into main Sep 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant