NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

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 getBalance at the start and warn before credit runs out. A run that hits ERROR_ZERO_BALANCE halfway 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