Glossary
robots.txt: the crawl rules a site publishes
robots.txt is a plain text file at the root of a domain where the owner tells automated clients which paths they may fetch.
What the file is
Every host can publish a file at /robots.txt, for example https://example.com/robots.txt. It follows the Robots Exclusion Protocol, which was formalized as RFC 9309 in 2022 after decades of informal use. Search engines read it before crawling, and well behaved scrapers do the same. It is a request, not a lock: nothing in the protocol stops a client from ignoring it, but ignoring it is a clear signal of bad manners and can matter if a dispute ever arises.
The syntax in brief
The file is made of groups. Each group starts with one or more User-agent lines and continues with Allow and Disallow rules.
User-agent: *
Disallow: /cart/
Disallow: /search
Allow: /search/help
User-agent: PriceWatchBot
Disallow: /
Sitemap: https://example.com/sitemap.xml
- A crawler uses the group whose user agent token matches its own name most specifically, and falls back to
*. - Rules match path prefixes. The longest matching rule wins, so
Allow: /search/helpbeatsDisallow: /searchfor that path. *inside a path is a wildcard and$anchors the end of the URL.Sitemaplines point to the site's URL lists and apply to everyone.
Crawl-delay and rate
Some files include Crawl-delay: 10, meaning wait ten seconds between requests. It is not part of RFC 9309 and Google ignores it, but it tells you what the owner considers a fair pace. Honoring it, or at least staying well under it, is a cheap way to avoid triggering rate limits and challenge pages in the first place.
Reading it in code
Python ships a parser in the standard library, so checking a URL before you fetch it takes a few lines.
from urllib.robotparser import RobotFileParser
rules = RobotFileParser("https://example.com/robots.txt")
rules.read()
target = "https://example.com/products/42"
if rules.can_fetch("PriceWatchBot", target):
print("allowed, pause", rules.crawl_delay("PriceWatchBot") or 1, "s")
else:
print("skip", target)
Fetch the file once per host and cache it for a day or so; there is no need to download it before each request. Frameworks such as Scrapy can obey it automatically through a setting.
What robots.txt does not do
It does not hide pages, protect data or grant permission. A path missing from the file is not an invitation, and the site's terms of service and data protection law still apply (see GDPR and scraping). It also does not stop bot protection: a path that robots.txt allows may still sit behind a Cloudflare check or a reCAPTCHA. Those are separate decisions made by separate systems. If your use is legitimate, such as monitoring public prices, you can solve a challenge on an allowed page with a token task; if robots.txt disallows the path, leave it alone.
Common questions
Is following robots.txt a legal requirement?
The protocol itself is voluntary, but courts and regulators may look at whether a crawler respected it. Treat it as a rule you follow.
Which user agent group applies to my crawler?
The group whose User-agent token matches your crawler name most specifically. If none matches, the asterisk group applies.
Does Google honor the Crawl-delay line?
No, Google sets its own pace. Other crawlers may respect it, and a scraper can use it as a guide for a polite request rate.
How often should I re-read robots.txt?
Caching it for about a day per host is common. Re-read it when a crawl starts and when the job runs for a long time.
If robots.txt allows a page, can it still show a CAPTCHA?
Yes. Bot protection is configured separately, so an allowed path can still be guarded by a challenge.
Keep reading
- Web crawlingWeb crawling discovers pages by following links outward from seed URLs, managed through a crawl frontier that decides what to fetch next.
- CrawlerA crawler is the program that walks a site link by link; politeness rules decide whether it behaves like a good guest.
- Is web scraping legal?General principles that shape whether a scraping project is lawful: public access, site terms, personal data, copyright and how you collect.
- Rate limitingCaps on requests per IP, key or session, the 429 response that enforces them, and the limit GateSolver applies to its own API.