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
source | Behavior |
|---|---|
auto | The sitemap, or links when there is no sitemap. This is the default. |
sitemap | Only the sitemap. Without one the crawl fails with sitemap_not_found. |
links | Only 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
concurrencyis the number of pages fetched at the same time, from 1 to 10.delay_msis the pause between requests, up to 10 seconds.respect_robotsis 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:
- pauses for as long as
Retry-Afterasks, and without that header for 30 seconds and longer each time, - continues with one page at a time, with at least a second between requests,
- 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"])status | Meaning |
|---|---|
queued | Waits for a free place |
running | Pages are being fetched |
completed | Finished, results are ready |
canceled | Stopped by you, the collected pages are kept |
failed | No results, the reason is in error |
stop_reason | Why it ended |
|---|---|
finished | There are no more addresses |
max_pages | The page limit was reached |
no_tokens | Fewer tokens were left than max_pages |
max_time | The crawl ran for 2 hours |
throttled | The server kept refusing requests despite pauses |
canceled | You stopped it |
interrupted | The 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.
GET /v1/crawls/{id}/pageslists pages with search, sorting and filters.GET /v1/crawls/{id}/pages/{page_id}returns all data of one page.POST /v1/crawls/{id}/extractextracts data with CSS selectors.GET /v1/crawls/{id}/downloadreturns one SQLite file with everything.
Problems
summary.issues has the number of pages with each problem. Use the same names in the issue parameter of the list of pages:
issue | Meaning |
|---|---|
server_error | Status 5xx |
client_error | Status 404 and other 4xx |
too_many_requests | Status 429 |
failed | The page could not be fetched |
robots_blocked | Skipped because of robots.txt |
redirected | The address redirects |
slow | Fetching took over 2 seconds |
missing_title | No title |
long_title | Title over 60 characters |
duplicate_title | The same title on another page |
missing_description | No meta description |
long_description | Meta description over 155 characters |
duplicate_description | The same meta description on another page |
missing_h1 | No h1 |
multiple_h1 | More than one h1 |
noindex | The page may not be indexed |
other_canonical | The canonical points to another address |
missing_alt | Images 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.