Skip to content

How the crawler is polite

A polite crawler costs a site almost nothing, and it stops when the site says no. The package keeps these rules in its code. You cannot turn them off with an option.

The speed of a polite crawler is the number of hosts in progress, divided by the rest for each host. Thus the crawler keeps one request in progress for each host, and it fetches from many hosts in parallel. The live crawl on the home page uses this scheduler.

The rest between two requests to one host is the longest of these times:

  • 3 seconds for a web page, and 1 second for a documented API.
  • 5 times the duration of the last request, to a maximum of 30 seconds. A slow server gets more rest.
  • The Crawl-delay of robots.txt, to a maximum of 60 seconds.
  • The Retry-After of a 429 or a 503. Without it, a random backoff that grows with each failure, to a maximum of 5 minutes.

A 401 or a 403 stops the host for 1 hour. A challenge page or a 402 stops it for 24 hours. The crawler does not try again with a different identity, a proxy or a browser in disguise. Crawler.resetHosts() ends the stops before their time.

Five errors in sequence stop a host for 1 hour. An error is no response, or a status, for example 500. Another 4xx, for example 400 or 422, is an error of the request and not of the host, so it does not count. A 429, 502, 503 or 504 does not stop the host. The host waits, for the time of Retry-After or for a backoff of up to 5 minutes. A Retry-After of more than 1 hour stops the host for that time, to a maximum of 30 days.

Test what each response means:

rate-limitedThe site limits the rate. The host waits until Retry-After, or for a backoff with jitter.
Wait from Retry-After
120 s
Note
none

The default header is:

PoliteCrawler/0.7.13 (+https://mark1russell7.github.io/crawler/bot/)

The link goes to a page for site owners. The contact option adds an address to the header. An email address also goes into the From header, and a URL does not, because From holds only a mailbox. The crawler sends no contact without it.

For each web page, the crawler reads the robots.txt of the site first and obeys it, as RFC 9309 specifies. When the crawler cannot read robots.txt, because of a dead domain, a broken certificate or a server error, it fetches nothing from the site. A documented public API follows its own terms. Test a robots.txt.

When the store has a copy of a page, the request includes its ETag and its Last-Modified date. A site that answers 304 Not Modified sends no body, and the crawler reads the stored copy again.

A server examines If-None-Match first, and it ignores If-Modified-Since when the request has the two (RFC 9110, section 13.1.3). Some sites give a different ETag at each response, for example one for each edge server. Such a site sends the full page at each visit, also when its Last-Modified date is stable. Thus the crawler keeps a validator memo for each host:

  • After 3 full responses in sequence with the stored body, it stops the ETag for the host and sends only the date.
  • After 20 such requests, or after 7 days, it sends the ETag again one time. A 304 starts the ETag again.
  • When the date alone also fails, it sends the two validators again, because they cost nothing.

The memo is in hosts.sqlite, so the processes on one store share it, and it stays after a restart.

A site can state the uses of its content in robots.txt or in a header. Two formats exist: the Content-Signal lines of Cloudflare, and the ai-use of the IETF AIPREF draft. When a page refuses AI input, the crawler keeps the page but holds back its text from an AI reader. A training opt-out (ai-train=no) does not apply, because the crawler trains no model. The crawler also records the RSL License lines of robots.txt and the TDMRep reservation (tdm-reservation and tdm-policy, in a header or a <meta> tag) with each capture. These records do not change what it does.