Skip to content

hisham-stack/journal-export-1177

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

journal-export-1177

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.

Prerequisites

  • Python 3.10+
  • A Swedish BankID (Mobile BankID or BankID on card)

Installation

# 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

Running

# Activate the virtual environment (if not already active)
source venv/bin/activate

# Run the scraper
python scraper.py

A 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:

  1. Navigate to Journalen → Anteckningar
  2. Load all records (clicking "Visa alla" if present)
  3. Expand each record to retrieve its full content
  4. Save the results to the output/ directory

Progress is printed to the terminal and written to scraper.log.

Output

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.

How it works

Step Function Description
1 do_login() Opens journalen.1177.se and waits up to 2 min for BankID redirect
2 navigate_to_anteckningar() Clicks JournalenAnteckningar 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

Dependency management

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.txt

Logs

scraper.log is written to the project root on every run and contains timestamped info and error messages. It is git-ignored.

About

Playwright-based exporter that automates the extraction of personal medical journal entries (Anteckningar) from journalen.1177.se into structured Markdown and JSON files, following manual BankID authentication.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors