A Playwright-based scraper that exports personal medical journal entries (Anteckningar) from journalen.1177.se into structured Markdown and JSON files. Authentication is performed manually via BankID in the browser window that the script opens.
- Python 3.10+
- A Swedish BankID (Mobile BankID or BankID on card)
# Clone and enter the project
git clone <repo-url>
cd journal-export-1177
# Create and activate a virtual environment
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install Python dependencies
pip install -r requirements.txt
# Install the Chromium browser used by Playwright
playwright install chromium# Activate the virtual environment (if not already active)
source venv/bin/activate
# Run the scraper
python scraper.pyA Chromium browser window will open and navigate to journalen.1177.se. You have 2 minutes to complete BankID authentication. Once logged in, the script will automatically:
- Navigate to Journalen → Anteckningar
- Load all records (clicking "Visa alla" if present)
- Expand each record to retrieve its full content
- Save the results to the
output/directory
Progress is printed to the terminal and written to scraper.log.
output/
├── md/
│ └── YYYY-MM-DD.md # One file per date; all records for that day
└── json/
└── journal_YYYY-MM-DD.json # All records combined, exported today
Each Markdown file groups records by date and includes the record type, author, and care provider. The JSON file contains the same data as an array of objects, suitable for further processing.
Note: Output files contain sensitive personal medical data. The
output/directory is git-ignored and should never be committed or shared.
| Step | Function | Description |
|---|---|---|
| 1 | do_login() |
Opens journalen.1177.se and waits up to 2 min for BankID redirect |
| 2 | navigate_to_anteckningar() |
Clicks Journalen → Anteckningar in the nav bar |
| 3 | load_all_records() |
Clicks "Visa alla", then polls the DOM until all <li> elements match the total reported by the page |
| 4 | extract_all_records() |
Clicks each record's expander button, waits for the AJAX content to load, and converts the HTML to Markdown |
| 5 | save_results() |
Groups records by date and writes the Markdown and JSON output files |
Direct dependencies are listed in requirements.in. requirements.txt is the full pinned lockfile (including transitive dependencies) generated by pip-tools.
To update or regenerate the lockfile after changing requirements.in:
pip install pip-tools
pip-compile requirements.in
pip-sync requirements.txtscraper.log is written to the project root on every run and contains timestamped info and error messages. It is git-ignored.