An automated web scraping script that exports railway restriction data from strecken-info.de and saves it with timestamped filenames.
This Python script uses Selenium WebDriver to automate the process of:
- Accessing the strecken-info.de website
- Automatically handling cookie consent banners
- Navigating to the "Einschränkungen" (Restrictions) section
- Exporting the data as a CSV file
- Saving the file with a timestamp in the format
YYYY-MM-DD_HH-MM.csv - Running on a configurable interval (default: every 15 minutes)
- Python 3.x
selenium- Web automation librarywebdriver-manager- Automatic Chrome WebDriver management
- Install required packages:
pip install selenium webdriver-manager- Ensure you have Google Chrome installed
- Download from: https://www.google.de/intl/de/chrome/
- WebDriver Manager will automatically handle the ChromeDriver
python autoexport.pyThe script will:
- Perform the first export immediately
- Wait for the configured interval (default: 15 minutes)
- Repeat continuously until manually terminated with
Ctrl+C
Files are saved with timestamped filenames to prevent conflicts:
- Pattern:
YYYY-MM-DD_HH-MM.csv - Example:
2026-02-08_14-30.csv - Location: Configured in
DOWNLOAD_DIR(Look for your script configuration lon top)
DOWNLOAD_DIR = r"C:\Your\Custom\Path" # Use raw string (r"") for Windows paths
FETCH_INTERVAL_MIN = 15 # Interval in minutesTo run the browser in the background without showing the UI:
options.add_argument("--headless") # Uncomment this line- Browser Setup: Initializes Chrome WebDriver with download preferences
- Website Navigation: Opens https://strecken-info.de
- Cookie Handling: Automatically accepts cookie consent (direct button or iframe)
- Element Clicking: Click "Einschränkungen" menu
- Export Trigger: Clicks "Exportieren" button to initiate download
- Download Wait: Waits up to 60 seconds for file to appear
- File Rename: Renames downloaded file with timestamp (prevents conflicts)
- State Reset: Clears cookies and opens new tab for next cycle
- Countdown: Displays countdown timer until next fetch
- Repeat: Continues indefinitely until Ctrl+C is pressed
Common Issues:
- "Failed to click restrictions table": Increase
CLICK_TIMEOUTor check if website is accessible - "Download timeout - file not found": Increase
DOWNLOAD_TIMEOUTor verify the export works manually - Chrome not found: Install Google Chrome or check installation path
- The script runs indefinitely - use
Ctrl+Cto stop - Website maintenance may cause temporary failures (Rarely) - script will retry on next interval
Due to the dummy Selenium (or dummy me), the toggle "Einschränkungen" is not always off every time you close the tab. It could be sometimes not require you to click, which you can directly download it, but sometimes due to webside maintenance, the toggle is automatically off. To eliminate this uncertainty, the script will:
- Still click the toggle (It may close the toggle)
- Fail to click "export", shows download failure
- Guarantee the next download to be successful
So FETCH_INTERVAL_SEC is set as half of a minute (30 seconds) to make sure you are having exactly the period you want.
You may observe this situation by setting your fetching inverval to 60 seconds, and 1 minute every fetching. If you have a good idea how to fix this, please contact me.