Skip to content
Documentation

Crawl a site

Visit the pages of a site in the background and find their problems.

A crawl runs in the background. You start it, check its status and read the results.

Start

curl -X POST https://api.seoscraper.io/v1/crawls \
  -H "Authorization: Bearer ssk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com", "max_pages": 500}'

The response has status 202 and the id of the crawl. All options are in Start a crawl.

Where addresses come from

sourceBehavior
autoThe sitemap, or links when there is no sitemap. This is the default.
sitemapOnly the sitemap. Without one the crawl fails with sitemap_not_found.
linksOnly links, starting from the start page.

The sitemap is taken from robots.txt, or from /sitemap.xml, /sitemap_index.xml and /wp-sitemap.xml. The mode field of the crawl tells which source was used.

A crawl stays on one site. example.com and www.example.com are the same site. Other subdomains need include_subdomains. Files such as images, PDFs, styles and scripts are not visited.

Choose paths

include_paths and exclude_paths take up to 20 patterns each, written as in robots.txt. A pattern matches the beginning of the path, * is any text and $ is the end:

{
  "url": "https://example.com",
  "include_paths": ["/blog/"],
  "exclude_paths": ["/blog/tag/", "*?sort=", "*.html$"]
}

Be gentle

  • concurrency is the number of pages fetched at the same time, from 1 to 10.
  • delay_ms is the pause between requests, up to 10 seconds.
  • respect_robots is on by default. It obeys Disallow and Crawl-delay. Turn it off only for a site that is yours.

Our crawler introduces itself as SeoScraperBot/1.0. To block it on your site, add this to robots.txt:

User-agent: SeoScraperBot
Disallow: /

When the site answers 429

A server that gets too many requests answers 429, or 503 with a Retry-After header. The crawl then:

  1. pauses for as long as Retry-After asks, and without that header for 30 seconds and longer each time,
  2. continues with one page at a time, with at least a second between requests,
  3. fetches the rejected pages again, asking for each one at most 4 times.

Rejected attempts cost no tokens. The throttle field tells the number of pauses (count), the time between requests (delay_ms) and the end of the latest pause (resume_at).

The crawl ends with stop_reason: throttled when the server refuses 4 times in a row or asks for a pause longer than 15 minutes. Rejected pages stay in the results with status 429 and you can retry them.

Check the status

Repeat every few seconds until status is no longer queued or running:

import time
import requests

API = "https://api.seoscraper.io/v1/crawls"
HEADERS = {"Authorization": "Bearer ssk_YOUR_KEY"}

crawl = requests.post(API, headers=HEADERS, json={"url": "https://example.com"}, timeout=40).json()
while crawl["status"] in ("queued", "running"):
    time.sleep(3)
    crawl = requests.get(f"{API}/{crawl['id']}", headers=HEADERS, timeout=40).json()
    print(crawl["pages_done"], "of", crawl["pages_found"])
print(crawl["status"], crawl["stop_reason"])
statusMeaning
queuedWaits for a free place
runningPages are being fetched
completedFinished, results are ready
canceledStopped by you, the collected pages are kept
failedNo results, the reason is in error
stop_reasonWhy it ended
finishedThere are no more addresses
max_pagesThe page limit was reached
no_tokensFewer tokens were left than max_pages
max_timeThe crawl ran for 2 hours
throttledThe server kept refusing requests despite pauses
canceledYou stopped it
interruptedThe connection was lost, the collected pages are kept

Read the results

Results are ready when the crawl ends. Before that you get 409 crawl_not_ready.

Problems

summary.issues has the number of pages with each problem. Use the same names in the issue parameter of the list of pages:

issueMeaning
server_errorStatus 5xx
client_errorStatus 404 and other 4xx
too_many_requestsStatus 429
failedThe page could not be fetched
robots_blockedSkipped because of robots.txt
redirectedThe address redirects
slowFetching took over 2 seconds
missing_titleNo title
long_titleTitle over 60 characters
duplicate_titleThe same title on another page
missing_descriptionNo meta description
long_descriptionMeta description over 155 characters
duplicate_descriptionThe same meta description on another page
missing_h1No h1
multiple_h1More than one h1
noindexThe page may not be indexed
other_canonicalThe canonical points to another address
missing_altImages without the alt attribute

ok is also there: it counts pages with status 2xx.

Retry pages

POST /v1/crawls/{id}/retry fetches the selected pages again and replaces them in the results of the same crawl. GET /v1/crawls/{id}/urls returns the numbers of pages with a given problem:

pages = requests.get(f"{API}/{crawl['id']}/urls", headers=HEADERS, params={"issue": "too_many_requests"}, timeout=40).json()["pages"]
ids = [page["id"] for page in pages]
retry = requests.post(f"{API}/{crawl['id']}/retry", headers=HEADERS, json={"page_ids": ids}, timeout=40).json()

The response is a separate crawl with its own id, progress and tokens. Check it the same way, and when it ends read the results of the original crawl. Only one retry can run at a time, otherwise you get 409 retry_in_progress.

Pages with status 2xx stay unchanged when the new attempt fails. When a selected page has status 429, we fetch one page at a time from the start, at most one per second.

Stop and delete

POST /v1/crawls/{id}/cancel stops a crawl and keeps the pages collected so far. DELETE /v1/crawls/{id} removes the crawl with its results.