Tirsvad ece9067099
Publish wiki / publish-wiki (push) Successful in 9s
TirSystem/git-workflows: Publish wiki / publish-wiki (push) Successful in 17s
Publish wiki / wiki (push) Successful in 9s
TirSystem/git-workflows: Sync GitHub mirror metadata / sync-metadata (push) Successful in 8s
Merge pull request 'MIL-005: Add wiki in English, Danish and Bahasa Malaysia' (#27) from mil-005-wiki into main
2026-10-28 09:30:24 +01:00
2026-10-28 07:33:35 +01:00

🚀 Scraping Wiki

A small Python project from Udemy's 100 Days of Code: The Complete Python Pro Bootcamp: it drives Chrome with Selenium, opens the Wikipedia main page and prints the article count. It is for course participants who want to compare solutions and for visitors looking for ideas.

📚 Table of Contents

🧭 Overview

The lecture builds interaction.py in seven steps: create the file, import Selenium, initialise the Chrome driver, navigate to Wikipedia with get(), identify the HTML element with a CSS selector, find it with find_element and print its text, and a hint at the next lectures (clicking links and typing into search fields). Each step has a screenshot below and an explanation in the wiki (English, Danish and Bahasa Malaysia).

Part What it is
src/scraping_wiki/interaction.py The script: create_driver, open_main_page, read_article_count, main
src/scraping_wiki/constants.py The page URL, the CSS selectors and the Chrome options
tests/unit/ pytest tests with a fake driver; they start no browser
tests/e2e/ End to end test and screenshot capture; run only in Docker
docs/lecture-steps/ The code of each lecture step, as built up in the lecture
docs/screenshots/ One screenshot per lecture step
Dockerfile Headless Chromium for the end to end run

The lecture steps

Step 1: create interaction.py. Step 1: create the file

Step 2: import Selenium. Step 2: import Selenium

Step 3: initialise the Chrome driver. Step 3: initialise the Chrome driver

Step 4: navigate to the Wikipedia main page with get(). Step 4: navigate with get

Step 5: identify the HTML element. The article count is a link inside the div with the id articlecount, so the lecture uses the CSS selector #articlecount a. Wikipedia has since added a second link in that div: the first match (red) is now the number of active editors, and the article count (green) is #articlecount li:nth-of-type(2) a, the selector the program uses (see ADR-0002). Step 5: identify the element

Step 6: find the element with find_element and print its text. Step 6: find the element and print

Step 7: next lectures: click links and type into search fields. Step 7: future interactions

📋 Requirements

  • Python 3.13 or newer
  • Google Chrome (to run the script on your own machine; Selenium downloads the matching driver)
  • selenium, the only runtime dependency (installed with the project)
  • pytest, ruff and mypy for the tests and checks (installed with the dev extra)
  • Optional: Docker for the end to end run and the screenshots
  • Optional: Doxygen to build the API documentation

🛠️ Setup

Create a local virtual environment in the project folder:

python -m venv .venv

Activate it:

# Windows (PowerShell)
.venv\Scripts\Activate.ps1

# Windows (Git Bash)
source .venv/Scripts/activate

# Linux / macOS
source .venv/bin/activate

Upgrade pip and install the project with the test tools:

python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

Leave the environment with deactivate. The .env file in a clone is for personal tooling only; the project never reads or imports it.

▶️ Run

With the environment active, this opens Chrome, loads the Wikipedia main page, prints the article count and closes the browser:

python -m scraping_wiki.interaction

The install also adds a console script, and --headless runs without a browser window:

scraping-wiki --headless

The output is one line, for example 7,256,081.

🧪 Tests

The unit tests start no browser:

python -m pytest

Style and types:

python -m ruff check src tests
python -m mypy src tests

The end to end test and the screenshots need a browser, so they run in a Docker container and never on your desktop. The results (log, exit code and screenshots) land in results/:

docker build -t scraping-wiki-e2e .
docker run --rm -v "$(pwd)/results:/results" scraping-wiki-e2e

Build the API documentation from the Doxygen comments (written to docs/doxygen/):

doxygen Doxyfile

📄 License

GNU Affero General Public License v3.0.

📎 Appendix: Project documents

The documents a newcomer needs, in reading order.

Document What it tells you
AGENTS.md The rules AI agents follow in this repository
Business Case Why the project exists, its scope and success criteria
Stakeholder Analysis Who is involved; the stakeholder IDs used for owners and reviewers
Project Plan The gateways and their schedule
Milestones One document per gateway: Go/No-Go criteria and tasks
Architecture decisions Why the layout is flat and why the selector changed
Review records The review of each document and of the code
Artifact registry Where each artifact type lives, the next version, the PO language and domain
Framework README The framework this project uses
Framework changelog What changed in each framework release

S
Description
Udemy 100 Days of Code: scrape the Wikipedia main page with Selenium and print the article count. Python 3.13+, tested, with screenshots per lecture step and a wiki in English, Danish and Bahasa Malaysia.
Readme AGPL-3.0
1.1 MiB
Languages
Python 94.4%
Dockerfile 3%
Shell 2.6%