Sub topic 17
Scheduling and headless command-line crawls
This chapter assumes you can run a crawl in the GUI, know the Internal tab, and have a saved configuration. Command-line crawling needs a paid licence. The free version cannot run headless.
Why run crawls headlessly
A headless crawl runs without opening the interface. It suits a weekly check on your own site, because the same configuration runs every time and the output lands in a predictable folder. You can then compare crawls (see the earlier chapter on saving and comparing) or process the CSV with a script.
Running a crawl from the command line
The command below crawls a site, saves the crawl file and exports the Internal tab into a timestamped folder.
screamingfrogseospider --crawl https://www.example.com \
--headless \
--save-crawl \
--output-folder /tmp/sf-crawl \
--timestamped-output \
--export-tabs "Internal:All"Each option does one job:
| Option | Effect |
|---|---|
| `--crawl` | Starts a crawl of the given URL |
| `--headless` | Runs without the GUI |
| `--save-crawl` | Saves the crawl file when finished |
| `--output-folder` | Sets where outputs are written |
| `--timestamped-output` | Creates a dated subfolder for each run |
| `--export-tabs` | Exports a tab and filter, written as `Tab:Filter` |
To reuse your scoped settings, add --config with the path to a saved configuration file. Without it, the crawl uses default settings, so your include and exclude rules are not applied.
Processing the export
The exported CSV is plain text, so a short script can read it. This one prints every URL that returned a 4xx or 5xx status code.
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"])The utf-8-sig encoding strips the byte order mark that some exports include. Without it, the first column name can be read incorrectly. With --timestamped-output, the file sits inside a dated subfolder, so adjust the path to match your run.
Scheduling
You can schedule in two ways.
- Built-in scheduler. In the GUI, open File > Scheduling to set a start time, crawl settings and exports. The application must be installed and the machine must be on at that time.
- System scheduler. Call the command above from cron on Linux or macOS, or Task Scheduler on Windows. This suits servers, where you control the environment.
Common errors
- Nothing is exported. The tab name is misspelled. Check it against the names in the GUI.
- Crawl is far larger than expected. The configuration file was not loaded, so your exclude rules did not apply.
- The job fails on a server. The licence is not activated for the user running the job, or the machine has too little memory. Large sites may need database storage mode.
- Old files are overwritten. Without
--timestamped-output, each run writes to the same folder.
Exercise
A cron job runs your headless crawl every Monday, but the crawl follows thousands of session-ID URLs that your GUI crawls skip. What is the likely cause, and how do you fix it?
Show answer
The command line crawl is not loading your saved configuration, so the Exclude rule for the session parameter is not applied. Add --config with the path to your saved configuration file to the command.
Exercise
Why would you add --timestamped-output to a weekly scheduled crawl?
Show answer
Each run writes to its own dated folder, so earlier results are kept and you can compare crawls over time instead of overwriting them.