Sub topic 17
Scheduling and headless command-line crawls
This chapter assumes you can already run a scoped crawl in the desktop app and save a configuration file. You should also be comfortable with a shell (bash or PowerShell) and with reading a CSV file. Here you will move a crawl you run by hand into a job that runs unattended, writes its results to disk, and is checked by a script.
Why automate a crawl
A single audit shows the site as it is today. A crawl that runs every week shows when something breaks: a deploy that adds noindex to a template, a redirect rule that creates a loop, or a section that loses its internal links. Scheduled crawls produce the dated snapshots you need for the comparison workflow from the previous chapters.
There are two ways to automate:
- The built-in scheduler in the desktop app (File > Scheduling). It is configured through a dialog and needs the app's machine to be on.
- The command line (headless mode). You start the Spider from a script, cron job, Task Scheduler entry or CI runner, and no window opens.
Both need a paid licence. The free version cannot save crawls, load a configuration or run on a schedule.
Choosing between the scheduler and the command line
| Need | Built-in scheduler | Command line |
|---|---|---|
| Setup effort | Dialog, no scripting | Shell script and a system scheduler |
| Run on a server without a display | Needs the app and a desktop session | Works headless |
| Post-process results (alerts, diffs) | Limited to exports and emailing | Any script can follow the crawl |
| Version control of the job | Stored in app settings | Script and config file can live in git |
| Chain several sites | One task per site | Loop over sites in a script |
For a single site you check by eye, the scheduler is enough. For alerts or several sites, use the command line.
Prepare a configuration file
The command line does not know your include rules, exclude rules, speed or user-agent unless you give it a configuration file. Build it in the app:
- Set up the crawl as you want it: scope, limits, robots.txt handling, rendering mode, custom extraction.
- Choose File > Configuration > Save As and save a
.seospiderconfigfile, for exampleweekly.seospiderconfig. - Pass that file to the CLI with
--config.
Keep the configuration file in version control next to your script. A crawl that silently changed settings is hard to compare with an older one.
A first headless crawl
The command below crawls a site you own, saves the crawl file and exports the Internal tab.
screamingfrogseospider --crawl https://www.example.com \
--headless \
--save-crawl \
--output-folder /tmp/sf-crawl \
--timestamped-output \
--export-tabs "Internal:All"What each option does:
--crawlstarts a Spider-mode crawl of the given URL.--headlessruns without opening the interface.--save-crawlwrites the finished crawl to a.seospiderfile, so you can reopen it in the app later.--output-folderis where exports and the crawl file go.--timestamped-outputputs each run in its own dated subfolder. Without it, a later run writes to the same folder and can overwrite or mix with earlier files.--export-tabs "Internal:All"exports a tab and filter pair. The format isTab:Filter, and the file is named after it, hereinternal_all.csv.
The executable name depends on the platform. On Linux it is screamingfrogseospider. On Windows it is ScreamingFrogSEOSpiderCli.exe in the install folder. On macOS you call the launcher inside the app bundle. Check the "Command Line" page of the official user guide for your version, because option names can change between releases.
Adding the config, reports and bulk exports
A fuller job loads your configuration and exports more than one tab:
screamingfrogseospider --crawl https://www.example.com \
--headless \
--config /srv/seo/weekly.seospiderconfig \
--save-crawl \
--output-folder /srv/seo/crawls \
--timestamped-output \
--export-tabs "Internal:All,Response Codes:Client Error (4xx),Page Titles:Missing" \
--bulk-export "Links:All Inlinks"--export-tabs takes a comma-separated list of Tab:Filter pairs. --bulk-export produces the same data as the Bulk Export menu, such as all inlinks, which is the file you need to find the pages that link to a broken URL. The --report option exports entries from the Reports menu. Run the program with --help to list the exact names your version accepts. A misspelled tab or filter name is a common reason an expected file is missing, so check the output folder after the first run.
Process the export with a script
The point of a headless crawl is that a script can read the result. This script reads the Internal tab and prints every URL with a 4xx or 5xx status:
import csv
with open("/tmp/sf-crawl/internal_all.csv", newline="", encoding="utf-8-sig") as f:
for row in csv.DictReader(f):
if row["Status Code"].startswith(("4", "5")):
print(row["Status Code"], row["Address"])Two details matter. The utf-8-sig encoding strips the byte-order mark that the export can start with, which would otherwise corrupt the first column name. And the column names, Status Code and Address, must match the export header exactly.
With --timestamped-output, the CSV is inside a dated subfolder, so a fixed path breaks. This version finds the newest run and exits non-zero when errors exist, which lets cron or a CI job flag the failure:
import csv
import sys
from pathlib import Path
root = Path("/srv/seo/crawls")
runs = sorted(p for p in root.iterdir() if p.is_dir())
if not runs:
sys.exit("No crawl folders found")
latest = runs[-1]
errors = []
with open(latest / "internal_all.csv", newline="", encoding="utf-8-sig") as f:
for row in csv.DictReader(f):
if row["Status Code"].startswith(("4", "5")):
errors.append((row["Status Code"], row["Address"]))
for code, url in errors:
print(code, url)
sys.exit(1 if errors else 0)Sorting by name picks the newest run only if the folder names sort by date, which is the case for the timestamp format the tool uses. If you add your own subfolders to the root, filter them out.
Schedule the job
Wrap the crawl and the check in one shell script, then ask the operating system to run it.
On Linux or macOS, a crontab entry that runs every Monday at 03:00:
0 3 * * 1 /srv/seo/weekly-crawl.sh >> /srv/seo/cron.log 2>&1On Windows, create a Task Scheduler task that runs the script or batch file. Run it under an account that has the licence and can write to the output folder.
Common problems
- Licence not found. The headless process needs the same licence as the desktop app on that machine. Enter the licence in the app once under the same user account that runs the job.
- Nothing appears in the output folder. Check that the folder exists and is writable, and that tab and filter names are spelled as in the app.
- Crawl differs from the one in the app. You did not pass
--config, so the defaults applied. - Job runs but the crawl is incomplete. The machine ran out of memory on a large site. Use database storage mode for big sites, as covered in the storage chapter.
- Pages behind a login are missing. Forms authentication is set up in the app. Pass the saved settings through the configuration, and test with a manual run first.
- Unexpected load on your server. Scheduled crawls run unattended, so set a sensible speed limit in the configuration and schedule them outside peak hours.
Exercise
Your cron job runs screamingfrogseospider --crawl https://www.example.com --headless --output-folder /srv/seo/crawls --export-tabs "Internal:All". It works, but each week's internal_all.csv overwrites the previous one, and the crawl cannot be reopened in the app. Which two options do you add, and why?
Show answer
Add --timestamped-output so each run writes to its own dated subfolder and old results are kept, and --save-crawl so the full crawl is saved as a .seospider file you can reopen and compare. You would also add --config with a saved configuration file so that the scoped settings match your manual crawls.
Exercise
A check script that opens /srv/seo/crawls/internal_all.csv fails with "file not found" after you enable timestamped output. What is the cause, and how do you fix the script?
Show answer
With timestamped output, the CSV is written inside a dated subfolder of the output folder, so the fixed path no longer exists. Fix the script to list the subfolders, pick the newest one (names sort by date), and open internal_all.csv inside it.