Web scraping
How do I run a scraper on a schedule?
Put it on a server and let cron or a systemd timer start it, then add a lock so runs never overlap and an alert so a failed run does not go unnoticed.
The common options
On a Linux server, cron is the classic choice: one line starts your script at fixed times. A systemd timer does the same with better logging and retry options. If you do not run a server, a scheduled job in your CI system or a cloud function triggered by a scheduler works for short jobs. Workflow tools such as n8n can also trigger scrapers and pass their results on. Pick the one your team already uses; the scheduler matters less than what you build around it.
Cron in two lines
# run every day at 06:15 server time, keep a log, never overlap
15 6 * * * cd /srv/price-watch && flock -n /tmp/price-watch.lock ./venv/bin/python run.py >> logs/run.log 2>&1
flock -n skips the run if the previous one is still going, which prevents two copies from hammering the same site and writing the same rows. Use absolute paths and a virtual environment, because cron starts with a minimal environment that differs from your shell.
A systemd timer instead
Timers let you check status with systemctl list-timers and read logs with journalctl. They also support Persistent=true, which runs a missed job after the server comes back from downtime.
# /etc/systemd/system/price-watch.timer
[Timer]
OnCalendar=*-*-* 06:15:00
RandomizedDelaySec=600
Persistent=true
[Install]
WantedBy=timers.target
A matching price-watch.service holds the command. RandomizedDelaySec adds jitter so your requests do not land at the same second every day.
What to build around the schedule
- Exit codes. Make the script exit non-zero on failure so the scheduler and your monitoring can see it.
- Alerts. Send a message to your team chat or email when a run fails or returns far fewer items than usual. A silent scraper that saves nothing for a week is the most common failure.
- Retries with backoff. Retry transient errors inside the run with exponential backoff; do not rely on the next scheduled run.
- Idempotent writes. Upsert by a natural key such as URL plus date, so a rerun does not duplicate rows.
- A balance check. If the job solves CAPTCHAs, call
getBalanceat the start and warn before credit runs out. A run that hitsERROR_ZERO_BALANCEhalfway leaves partial data.
Choosing the frequency
Match the schedule to how often the data changes and how fresh you need it. Prices in fast markets may justify hourly runs; catalog details rarely need more than daily. Every run costs the target site load and costs you proxies and solves, so the right frequency is the lowest one that still answers the business question. The page on reducing scraping costs has more on this.
Containers and cloud runs
If your scraper runs in a container, the scheduler starts the container instead of the script. Keep state such as cookies and the last cursor in a volume or a small database, not inside the container, because each run starts fresh. The glossary page on containerized scraping covers images and resource limits, and monitoring scraper health explains which numbers to track over time.
Time zones and daylight saving
Cron uses the server's time zone. If the target site updates prices at local midnight in another country, schedule relative to that, and remember that daylight saving shifts both sides twice a year. Running servers in UTC and converting in your head, or in the timer definition, avoids surprises.
Write the schedule down next to the scraper's code, with the reason for the chosen time, so the next person who touches it knows why it runs at 06:15 and not at midnight.
Common questions
Why does my script work by hand but fail in cron?
Cron uses a minimal environment and a different working directory. Use absolute paths and set needed variables in the command.
How do I stop two runs from overlapping?
Wrap the command with flock -n, or use a lock file or database lock inside the script.
Is a CI scheduler fine for scraping?
For short jobs, yes. Long jobs may hit runner time limits and run from shared IPs.
Should every run start at the same minute?
Adding a few minutes of random delay spreads load and looks less mechanical.
How do I know a scheduled run failed?
Exit with a non-zero code and alert on it, plus alert when the item count drops far below normal.
Keep reading
- How do I monitor a scraper in production?Track responses, record counts, field coverage, challenge frequency and cost per site, and alert on changes rather than fixed thresholds.
- Containerized scrapingPackaging scrapers and their browsers into containers so the same worker runs anywhere and scales out by adding copies.
- Exponential backoffRetrying with delays that double each time plus random jitter, the standard response to 429 and 5xx errors.
- Price monitoring with AI agents and CAPTCHAsAn architecture for a price monitoring agent that visits shop pages on schedule, meets challenges and still delivers clean numbers.