Files
Tirsvad 9dc37db209 Write the English wiki pages
Task: MIL-005#1
Closes #29
2026-10-28 14:35:00 +08:00

2.7 KiB

English · Dansk · Bahasa Melayu

Top 100 movies

Lecture: The 100 movies project. The goal is movies.txt with the titles numbered from 1) upwards. The code is empire_movies.py (parsing), movie.py (reverse and number) and movie_file.py (writing).

Step 1: choose the page

The assignment pins an Internet Archive snapshot of Empire's list, because live sites change. The screenshot shows the saved headings of the page.

Step 1: the page

What we gained: a pinned snapshot makes a scraper repeatable.

Step 2: inspect the markup

The 2020 page has <h3 class="title">; the current page has <h2><strong> headings that start with a rank.

Step 2: markup

What we gained: when a site changes its markup, the parser must change with it, so we keep both layouts covered.

Step 3: titles in page order

select("h3.title") and a list comprehension over get_text(). The page counts down from 100.

Step 3: titles

What we gained: a list comprehension is the compact way to collect text from many tags.

Step 4: reverse the list

titles[::-1] makes the list count up from 1.

Step 4: reversed

What we gained: slicing with a negative step reverses a list in one expression.

Step 5: write movies.txt

A with open(...) block writes one title per line.

Step 5: write

What we gained: the context manager closes the file for us, and the same run always gives the same file.

Step 6: the result

Step 6: movies.txt

What we gained: a personal watch list from a website, ready to pick a film from at random.

Note on the data

movies.txt was produced from the current Empire list on 2026-10-28, so its ranking differs from the 2020 list in the lecture. The Internet Archive answered 429 Too Many Requests while we built this, so the snapshot layout is covered by a hand-written sample in the tests.

What we gained

We can scrape a ranked list, put it in the order we want and save it to a file.